我想更改Background
, FontWeight
, Foreground
in dxg:GridColumn
。我写了这段代码,但不幸的是它不起作用。我该如何解决?
public class CellViewModel {
public string Value { get; set; }
public string FontWeight { get; set; }
public string Foreground { get; set; }
public string Background { get; set; }
}
public class TestItemViewModel {
public CellViewModel Column1 { get; set; }
public CellViewModel Column2 { get; set; }
public CellViewModel Column3 { get; set; }
}
public class TestViewModel {
public TestViewModel() {
this.Items = new ObservableCollection<TestItemViewModel> {
new TestItemViewModel {
Column1 = new CellViewModel { Value = "CCC", FontWeight = "Bold", Foreground = "Red", Background = "Green" },
Column2 = new CellViewModel { Value = "-683,84", FontWeight = "Normal", Foreground = "Red", Background = "SeaGreen" },
Column3 = new CellViewModel { Value = "-683,84", FontWeight = "Normal", Foreground = "Red", Background = "SeaGreen" },
}
};
}
public ObservableCollection<TestItemViewModel> Items { get; set; }
}
<dxg:GridControl HorizontalContentAlignment="Right"
AutoPopulateColumns="False"
ItemsSource="{Binding Path=Performance.Items}">
<dxg:GridControl.Resources>
<DataTemplate x:Key="GridColumnHorizontalContentAlignmentTemplate">
<dxe:TextEdit x:Name="PART_Editor" HorizontalContentAlignment="Right" />
</DataTemplate>
</dxg:GridControl.Resources>
<dxg:GridControl.Columns>
<dxg:GridColumn AllowColumnFiltering="False"
CellTemplate="{StaticResource GridColumnHorizontalContentAlignmentTemplate}"
FieldName="BuyAndHold.Value"
Header="Column 1"
HorizontalHeaderContentAlignment="Right">
<dxg:GridColumn.CellStyle>
<Style TargetType="dxg:CellContentPresenter">
<Setter Property="Background" Value="{Binding Path=Column1.Background}" />
<Setter Property="FontWeight" Value="{Binding Path=Column1.FontWeight}" />
<Setter Property="Foreground" Value="{Binding Path=Column1.Foreground}" />
</Style>
</dxg:GridColumn.CellStyle>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AllowEditing="False"
AllowGrouping="False"
AllowSorting="False"
NavigationStyle="None"
PrintTotalSummary="False"
ShowGroupPanel="False"
ShowHorizontalLines="False"
ShowIndicator="False"
ShowTotalSummary="False"
ShowVerticalLines="False" />
</dxg:GridControl.View>
</dxg:GridControl>
我不明白为什么会有
<Style TargetType="dxg:CellContentPresenter">
<Setter Property="Background" Value="{Binding Path=BuyAndHold.Background}" />
<Setter Property="FontWeight" Value="{Binding Path=BuyAndHold.FontWeight}" />
<Setter Property="Foreground" Value="{Binding Path=BuyAndHold.Foreground}" />
</Style>
没有数据绑定?
如果我手动设置值一切正常。例如。
<Setter Property="Background" Value="Red" />
工作正常。