WPF Listview - binding a text column to a combobox column selected item
I have a Listview:
<ListView ItemsSource="{Binding FieldMap.SourceTargetFieldMap, Mode=Default}">
<ListView.View>
<GridView>
<GridViewColumn Header="Source Fields" CellTemplate="{StaticResource sourceFieldsTemplate}"/>
<GridViewColumn Header="Source Values" CellTemplate="{StaticResource =sourceValueTemplate}">
<GridViewColumn Header="Target Field" CellTemplate="{StaticResource targetFieldTemplate}"/>
</GridView>
</ListView.View>
</ListView>
And I also have cell data templates that these bind to:
<DataTemplate x:Key="sourceFieldsTemplate">
<ComboBox x:Name="cbSourceField" SelectedValue="{Binding Path=SourceField, Mode=TwoWay}" DisplayMemberPath="FieldName" ItemsSource="{Binding SourceFieldValues}" Width="120" /开发者_开发技巧>
</DataTemplate>
<DataTemplate x:Key="sourceValueTemplate">
<TextBox x:Name="tbSourceValue" Margin="5,0,0,0" DataContext="{Binding ElementName=cbSourceField, Path=SelectedItem}" Text="{Binding Path=FieldValue, Mode=TwoWay}" TextWrapping="Wrap" Width="115" />
</DataTemplate>
<DataTemplate x:Key="targetFieldTemplate">
<TextBox x:Name="tbTargetField" Margin="5,0,0,0" Text="{Binding Path=TargetField}" TextWrapping="Wrap" Width="155" IsReadOnly="True"/>
</DataTemplate>
What I want to do is, bind the Source Value textbox field to the selected item of the SourceFields combobox. So when an item is selected from the sourcefield combobox, a property from the selectedItem (which is actually a object with two properties - something like fieldname and value) populates the textbox.
Both controls are "hidden" within datatemplates and I am not sure how to populate one from the other??
Any ideas? Much appreciated!!
Matt
You could insert a ContentConteol where content is bound to selected item of your listview - then the datetemplate should take care of displaying - I would set readonly on the textbox since altering the text will have no effect.
精彩评论