[英]Combobox selected item binding to GridViewColumn and GridViewColumn binding to combobox selected item
I am trying to have my selected combobox value = to the textbox value. 我试图将我选择的组合框值=设置为文本框值。 I want this to be in xaml only if possible.
我希望仅在可能的情况下将其保存在xaml中。
<ListView x:Name="ExampleLV" ItemsSource="{Binding Data.Example1Collection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Column1" DisplayMemberBinding="{Binding Values[0].Value}"/>
</GridView>
</ListView.View>
</ListView>
<ComboBox Name="ExampleCB" ItemsSource="{Binding Data.Example2Collection}"
SelectedItem="{Binding ElementName=ExampleLV,
Path=SelectedItem.Values[0].Value, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="Tag" Value="{Binding ElementName=ExampleLV, Path=SelectedItem.Tag, Mode=TwoWay}"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
The problem isn't that the selected List item isnt updating, rather the combobox selected updating isn't updating to match the listview selected item. 问题不在于所选列表项没有更新,而是组合框所选更新没有更新以匹配列表视图所选项。
And Yes, the Values[0].Value has the INotifyPropertyChanged interface. 是的,Values [0] .Value具有INotifyPropertyChanged接口。
I have not understood whether you need binding to listview(Question subject) or to Textbox(Question body). 我不了解您是否需要绑定到listview(问题主题)或Textbox(问题主体)。 Here is pure XAML solution for both of them:
这是它们的纯XAML解决方案:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
<StackPanel>
<ListView x:Name="ExampleLV" SelectedValue="{Binding ElementName=Cbox, Path=SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemsSource>
<x:Array Type="{x:Type sys:String}">
<sys:String>Test1</sys:String>
<sys:String>Test2</sys:String>
<sys:String>Test3</sys:String>
</x:Array>
</ListView.ItemsSource>
<ListView.View>
<GridView>
<GridViewColumn Header="Column1"/>
</GridView>
</ListView.View>
</ListView>
<TextBox Text="{Binding ElementName=Cbox, Path=SelectedValue, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"/>
<ComboBox x:Name="Cbox">
<ComboBox.ItemsSource>
<x:Array Type="{x:Type sys:String}">
<sys:String>Test1</sys:String>
<sys:String>Test2</sys:String>
<sys:String>Test3</sys:String>
</x:Array>
</ComboBox.ItemsSource>
</ComboBox>
</StackPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.