【发布时间】:2015-04-01 13:12:51
【问题描述】:
我成功地将集合绑定到 DataGrid,并且还成功地将属性绑定到 DataGridComboBoxColumn。 (有一个名为 snoop 的 WPF 工具可以让我调查数据是否已绑定)。
但由于某种原因,没有显示初始数据。只有在我手动更改选择之后。该值是可见的。
感谢任何提示或帮助!
谢谢,
这是我的 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?
-
是的,当然。我确定这不是绑定问题,因为我可以通过 snoop 或 WPF 检查器查看绑定值。在我看来,它一定是 XAML 中的东西