Tek*_*ito 5 wpf xaml datagrid styles datagridcomboboxcolumn
我正在尝试更改ElementStyleDataGrid ComboBox列.据说,TextBlock当控件未被编辑时,Style实际上是类型.因此,如其他示例所示,我尝试过:
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="Background" Value="Green" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
Run Code Online (Sandbox Code Playgroud)
当这个嵌入我的DataGridComboBoxColumn定义中时,我得到了这个奇怪的错误信息:
'TextBlock'TargetType与元素'TextBlockComboBox'的类型不匹配.
究竟是什么TextBlockComboBox?或者更重要的是,我怎样才能进入ElementStyle,因为定位ComboBox似乎没有做任何事情.
ElementStyle在这种情况下应该是 的类型ComboBox。我们有两种类型的 DataGrid,它运行 -DataGridRow和DataGridCell,第一个是线条,第二个是单元格。DataGridCell因此,默认情况下,所有内容都由not类型的单元格组成TextBlock's。
要确定另一列的类型,请使用DataGridTemplateColumn。因此,DataGridComboBoxColumn也许定义为:
<DataGridTemplateColumn Width="1.5*" IsReadOnly="False" Header="Position2">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="ComboBoxColumn" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
通过此设置可以进行任何类型的控制。
在您的情况下,您需要为以下内容创建样式DataGridCell:
<Style x:Key="StyleForCell" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Green" />
</Style>
Run Code Online (Sandbox Code Playgroud)
并像这样使用:
<DataGridComboBoxColumn x:Name="ComboBoxColumn"
CellStyle="{StaticResource StyleForCell}"
Header="Position"
SelectedItemBinding="{Binding Position}" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3776 次 |
| 最近记录: |