DataTemplate 和 ObjectDataProvider 刷新问题
我在 WPF 数据网格(WPF 工具包)中编辑单元格模板时遇到问题。该模板是使用 ComboBox 和 ItemsSource 构建的 ComboBox 在运行时加载。
这是平均代码...
<ObjectDataProvider x:Key="dataValuesProvider" MethodName="GetValues" />
<toolkit:DataGrid
ItemsSource="{Binding Path=MyItems}">
<toolkit:DataGridTemplateColumn
Header="Property1">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Property1, ValidatesOnDataErrors=true}"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox
SelectedValue="{Binding Path=Property1, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
IsEditable="True"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Source={StaticResource dataValuesProvider}, Mode=OneWay}"
/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellEditingTemplate>
</toolkit:DataGridTemplateColumn></toolkit:DataGrid>
现在,我遇到了这个问题。
我必须在每行上使用不同的值更新 dataValuesProvider 。然后我在数据网格的选择更改事件上插入了 dataValuesProvider (dataValuesProvider=null) 的重置。
(dataValuesProvider 将在所选行的特定单元格上输入后加载)。
这就是问题:当我重置 dataValuesProvider (在新行的选择更改时)它修改了 ComboBox 的 SelectedValue 并清除了上一行的 Property1 。
我认为存在这种行为是因为单元格的编辑模板在我编辑单元格之前不会更新绑定关联。是吗?
我该如何做才能避免这个问题?
I have a problem with a edit templete of cell in a WPF datagrid (WPF Toolkit). The template is builded with a ComboBox and the ItemsSource of
ComboBox are loaded at runtime.
This is the mean code...
<ObjectDataProvider x:Key="dataValuesProvider" MethodName="GetValues" />
<toolkit:DataGrid
ItemsSource="{Binding Path=MyItems}">
<toolkit:DataGridTemplateColumn
Header="Property1">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Property1, ValidatesOnDataErrors=true}"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox
SelectedValue="{Binding Path=Property1, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
IsEditable="True"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Source={StaticResource dataValuesProvider}, Mode=OneWay}"
/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellEditingTemplate>
</toolkit:DataGridTemplateColumn></toolkit:DataGrid>
Now, I have this problem.
I have to update the dataValuesProvider with different value on each rows. Then I have insert a reset of dataValuesProvider (dataValuesProvider=null) on selectionchanged event of datagrid.
(The dataValuesProvider will load after a input on a specific cell of the selected row).
This is the problem: when I reset the dataValuesProvider (on selectionchanged of a new row) it's modified the SelectedValue of ComboBox and the Property1 of previous row is cleared.
I think that there is this behavior becouse the editing template of cell not update the binding associations until I edit the cell. It's right?
How can I do to avoid this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有解决,
但是我已经定义了一个简单的项目来显示问题。
您可以从此链接下载:http://pollosky.it/ wp-content/uploads/2009/12/ObjectProviderTest.zip
尝试从第一行的第二个单元格中选择值,然后转到第二行。第一行属性值被清零!
我该怎么办?
I have not yet resolved
however I have defined a simple project that show the problem.
You can download it from this link: http://pollosky.it/wp-content/uploads/2009/12/ObjectProviderTest.zip
Try to selectvalue from the second cell of the first row and then go to the second row. The value of property of first row is cleared!
How can I do?