I am trying to have my selected combobox value = to the textbox value. I want this to be in xaml only if possible.
<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.
I have not understood whether you need binding to listview(Question subject) or to Textbox(Question body). Here is pure XAML solution for both of them:
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.