链接WPF对象到c#样式

本文关键字:样式 对象 WPF 链接 | 更新日期: 2023-09-27 18:10:24

我正在使用DevExpress的TreeList控件。我试着根据它们的值给一些细胞上色。我从这里得到了代码结构。然而,我的c#函数似乎没有链接到我的WPF对象。我如何将它们连接在一起以处理TreeList.NodeCellStyle事件?

样例代码

private void treeList1_NodeCellStyle(object sender, GetCustomNodeCellStyleEventArgs e) {
   // Modify the appearance settings used to paint the "Budget" column's cells
   // whose values are greater than 500,000.
   if (e.Column.FieldName != "Budget") return;
   if (Convert.ToInt32(e.Node.GetValue(e.Column.AbsoluteIndex)) > 500000) {
      e.Appearance.BackColor = Color.FromArgb(80, 255, 0, 255);
      e.Appearance.ForeColor = Color.White;
      e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
   }
}

WPF示例

<dxt:TreeListControl Name="treeList">
    <dxt:TreeListControl.Columns>
        <dxt:TreeListColumn FieldName="ClientID" Header="Heirarchy"/>
        <dxt:TreeListColumn FieldName="InstrumentID" />
        <dxt:TreeListColumn FieldName="OrderID" />
        <dxt:TreeListColumn FieldName="Status" />
        <dxt:TreeListColumn FieldName="OpenPosition" />
        <dxt:TreeListColumn FieldName="ExecPosition" />
        <dxt:TreeListColumn FieldName="CumOpenPosition" />
        <dxt:TreeListColumn FieldName="CumExecPosition" />
        <dxt:TreeListColumn FieldName="TransactionTime" />
        <dxt:TreeListColumn FieldName="LogTime" />
    </dxt:TreeListControl.Columns>
    <dxt:TreeListControl.View>
        <dxt:TreeListView Name="treeListView1" AutoWidth="True"
                          KeyFieldName="ID" ParentFieldName="ParentID" />
    </dxt:TreeListControl.View>
</dxt:TreeListControl>

链接WPF对象到c#样式

可以使用条件格式。
以下是WPF中的示例:

<dxt:TreeListControl.View>
    <dxt:TreeListView Name="treeListView1" AutoWidth="True"
                      KeyFieldName="ID" ParentFieldName="ParentID">
        <dxt:TreeListView.FormatConditions>
            <dxt:FormatCondition FieldName="Budget" Expression="[Budget] &gt; 500000">
                <dx:Format Foreground="White" Background="#50FF00FF" FontWeight="Bold"/>
            </dxt:FormatCondition>
        </dxt:TreeListView.FormatConditions>
    </dxt:TreeListView>
</dxt:TreeListControl.View>

c#相同:

treeListControl1.View.FormatConditions.Add(new FormatCondition()
{
    FieldName = "Budget",
    Expression = "Budget > 500000",
    Format = new Format()
    {
        Background = new SolidColorBrush(Color.FromArgb(80, 255, 0, 255)),
        Foreground = Brushes.White,
        FontWeight = FontWeights.Bold
    }
});