* UIListBox:修改对象绑定的显示问题

This commit is contained in:
Sunny 2021-06-03 11:51:04 +08:00
parent fb20fb38ce
commit 8aeca1b7c3
6 changed files with 25 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -628,11 +628,34 @@ namespace Sunny.UI
Color foreColor = isSelected ? ItemSelectForeColor : ForeColor;
Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1);
string showText = string.Empty;
if (DisplayMember.IsNullOrEmpty())
{
showText = Items[e.Index].ToString();
}
else
{
var list = Items[e.Index].GetType().GetNeedProperties();
foreach (var info in list)
{
if (info.Name == DisplayMember)
{
object defaultobj = info.GetValue(Items[e.Index], null);
showText = defaultobj.ToString();
}
}
if (showText.IsNullOrEmpty())
{
showText = Items[e.Index].ToString();
}
}
if (!otherState)
{
e.Graphics.FillRectangle(BackColor, e.Bounds);
e.Graphics.FillRoundRectangle(backColor, rect, 5);
e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, foreColor, e.Bounds, sStringFormat);
e.Graphics.DrawString(showText, e.Font, foreColor, e.Bounds, sStringFormat);
}
else
{
@ -650,7 +673,7 @@ namespace Sunny.UI
e.Graphics.FillRectangle(BackColor, e.Bounds);
e.Graphics.FillRoundRectangle(backColor, rect, 5);
e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, foreColor, e.Bounds, sStringFormat);
e.Graphics.DrawString(showText, e.Font, foreColor, e.Bounds, sStringFormat);
}
AfterDrawItem?.Invoke(this, Items, e);