我成功地将一个集合绑定到DataGrid,并成功将一个属性绑定到DataGridComboBoxColumn。 (有一个名为snoop的WPF工具,允许我调查数据是否已被绑定)。WPF DataGridComboBoxColumn不显示初始绑定值
但由于某些原因未显示初始数据。只有在手动更改选择后。该值显然可用。
任何提示或帮助表示赞赏!
谢谢
这是我的XAML:
<DataGridComboBoxColumn Width="*"
DisplayMemberPath="RedOms"
Header="MyHeader"
ItemsSource="{Binding Source={StaticResource MyModel},
Path=SRCollection,
Mode=OneWay}"
SelectedValueBinding="{Binding AZSR,
Mode=TwoWay}"
SelectedValuePath="ID">
<DataGridComboBoxColumn.CellStyle>
<Style BasedOn="{StaticResource EDGridCell}" TargetType="DataGridCell">
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding AZBev, Mode=OneWay}" Value="False">
<Setter Property="Background" Value="{StaticResource KlrColor}" />
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridComboBoxColumn.CellStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="Background" Value="{StaticResource KlrColor}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
这里是静态资源EDGridCell
<Style x:Key="EDGridCell" TargetType="{x:Type DataGridCell}">
<EventSetter Event="UIElement.PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Yellow" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
硬,没有看到你的对象说了。我假设你正确使用INotifyPropertyChanged? – 2015-04-01 13:21:21
是的,肯定。我确定这不是一个绑定问题,因为我可以通过snoop或WPF检查器查看绑定值。在我看来,它一定是XAML中的一些东西 – user1841243 2015-04-01 13:29:29