我试图从后面的代码创建DatagridComboBoxColumn
。如何将其与ElementStyle
和EditingElementStyle
?
我试图创建这个:
<DataGridComboBoxColumn Width="*" ElementStyle="{StaticResource ComboBoxElementStyle}" EditingElementStyle="{StaticResource ComboBoxEditingElementStyle}" />
来自:
private DataGridComboBoxColumn CreateComboValueColumn()
{
DataGridComboBoxColumn column = new DataGridComboBoxColumn();
column.ElementStyle = ???;
column.EditingElementStyle = ???;
return column;
}
哪个不显示comboBox:
我试图链接的风格:
<!-- ComboBox element and editing style -->
<Style x:Key="ComboBoxElementStyle" TargetType="{x:Type ComboBox}">
<Setter Property="ItemsSource" Value="{Binding ComboItems}"/>
<Setter Property="SelectedValue" Value="{Binding Value}" />
<Setter Property="DisplayMemberPath" Value="Text"/>
<Setter Property="SelectedValuePath" Value="ID" />
</Style>
<Style x:Key="ComboBoxEditingElementStyle" TargetType="{x:Type ComboBox}">
<Setter Property="ItemsSource" Value="{Binding ComboItems}"/>
<Setter Property="SelectedValue" Value="{Binding Value}" />
<Setter Property="DisplayMemberPath" Value="Text"/>
<Setter Property="SelectedValuePath" Value="ID" />
</Style>
答案 0 :(得分:1)
你好试试这样的事情:
private DataGridComboBoxColumn CreateComboValueColumn()
{
DataGridComboBoxColumn column = new DataGridComboBoxColumn();
column.ElementStyle = YourWindowName.FindResource("ComboBoxElementStyle") as Style;
column.EditingElementStyle = YourWindowName.FindResource("ComboBoxEditingElementStyle") as Style;
return column;
}
答案 1 :(得分:0)
尝试(Style)FindResource("StyleOne")
看看这里: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/resources-and-code