我有一个RadComboBox放在RadGridViewDataColumn里面。
<tk:RadGridView
Name="grdPeople"
ItemsSource="{Binding People}"
SelectedItem="{Binding SelectedPerson, Mode=TwoWay}">
<tk:GridViewDataColumn
DataMemberBinding="{Binding PeopleDetails}"
UniqueName="PeopleDetails"
Header="People">
<tk:GridViewDataColumn.CellTemplate>
<TextBlock
Text="{Binding Title}"/>
</tk:GridViewDataColumn.CellTemplate>
<tk:GridViewDataColumn.CellEditTemplate>
<tk:RadComboBox
DisplayMemberPath="TitleValue"
SelectedItem="{Binding Path=People.Title, Mode=TwoWay}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tk:RadGridView}}, Path=DataContext.Titles}"/>
</tk:GridViewDataColumn.CellEditTemplate>
</tk:GridViewDataColumn>
</tk:RadGridView>
我知道问题出在RadGridView和窗口数据上下文对象的混合上,但不确定为什么标题没有保存在数据库中?
相反,如果我把RadComboBox替换成普通的TextBox。
<TextBox
Width="50"
Text="{Binding Title}"
TextAlignment="Left"/>
在文本框中输入数值就能正常工作,把标题保存在DB中。
我猜测是RadGridView的单元格编辑模板中的各种组件混合的问题?
只要把SelectedItem绑定的路径从'People.Title'改为'Title'即可。
<tk:RadComboBox
DisplayMemberPath="TitleValue"
SelectedItem="{Binding Path=Title, Mode=TwoWay}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tk:RadGridView}}, Path=DataContext.Titles}"/>