我正在使用DevExpress的TreeList
控件。我试图根据它们的值在一些单元格中着色。我从here获得了代码结构。但是,我的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>
答案 0 :(得分:0)
您可以使用Conditional Formatting
以下是WPF
中的示例:
<dxt:TreeListControl.View>
<dxt:TreeListView Name="treeListView1" AutoWidth="True"
KeyFieldName="ID" ParentFieldName="ParentID">
<dxt:TreeListView.FormatConditions>
<dxt:FormatCondition FieldName="Budget" Expression="[Budget] > 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
}
});