我们有ListView和ComboBox。我在按钮点击时将数据绑定到listView。我想用选定的值显示组合框。当我们设置IsSynchronizedWithCurrentItem =“True”时它会更新组合框的所有值,但是当我们设置IsSynchronizedWithCurrentItem =“False”时,组合框不会显示选定的值。为什么?我使用MVVM模型为列表视图和组合框的绑定数据而不是硬编码。如果您有解决方案,请与我们分享。
<GridViewColumn Header="Part ID">
<GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadComboBox x:Name="PartIdListViewRadComboBox"
CanAutocompleteSelectItems="True" IsEditable="True"
Width="105" Height="30" Margin="4,4,4,4"
VerticalAlignment="Center" StaysOpenOnEdit="False"
IsSynchronizedWithCurrentItem="False"
SelectedValue="{Binding Path=ProductID}"
DisplayMemberPath="PartID" EmptyText="Part ID"
HorizontalAlignment="Left"
ItemsSource="{ Binding RelativeSource=
{RelativeSource FindAncestor,AncestorType={x:Type ListView}},
Path=DataContext.ProductModel.ListViewComboboxProductListCollection}"
OpenDropDownOnFocus="True"
TextSearchMode="Contains" IsFilteringEnabled="True"
IsTextSearchEnabled="True">
<!--
<ie:Interaction.Triggers>
<ie:EventTrigger EventName="SelectionChanged">
-->
<!--
<si:CallMethodAction MethodName="SelectionChanged"
TargetObject="{Binding}" /> -->
<!--
<ie:InvokeCommandAction Command="{Binding RelativeSource=
{RelativeSource FindAncestor,AncestorType={x:Type ListView}},
Path=DataContext.PartIdComboboxChangedComand}"
CommandParameter="{Binding ElementName=PartIdListViewRadComboBox}"/>
</ie:EventTrigger>
</ie:Interaction.Triggers>-->
</telerik:RadComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
答案 0 :(得分:0)
我的最后一个想法是使用ItemTemplate
:
<telerik:RadComboBox ... >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=PartID}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
...
</telerik:RadComboBox>