rrn

I have a ListView as shown below that uses a GridView

<ListView Name="MyEmployeeList" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=EmployeeData}" >

<ListView.View>

<GridView >

<GridViewColumn x:Name="col1" Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}" />

<GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}" />

</GridView>

</ListView.View>

</ListView>

Is it possible to bind a TextBlock Text property to ListView's SelectedItem but only to the first GridView Column Basically bind the TextBlock Text property to selectedItem on GridViewColumn "col1" I wanted to use the ElementName binding but not sure if it possible or what is the best approach.



Re: Windows Presentation Foundation (WPF) Binding a TextBlock to GridViewColumn's selectedItem

Douglas Stockwell

I'm not sure that you can abstract the binding directly to a column, but you can bind to the same value by using the same path (FirstName) explicitly:

<TextBlock Text="{Binding ElementName=MyEmployeeList, Path=SelectedItem.FirstName}" />

Although since you set IsSynchronizedWithCurrentItem="True", you don't need ElementName here, and can simply use Master-Detail binding. This will automatically pick up the "current" item.

<TextBlock Text="{Binding EmployeeData/FirstName}" />





Re: Windows Presentation Foundation (WPF) Binding a TextBlock to GridViewColumn's selectedItem

rrn

Thank you Doug. I'm aware of the solution you provided. I'm trying to learn the different ways by which you can do databinding in wpf and was curious to figure out if there is a way to bind directly to a column.