Binding using ElementName for a control within the Grid\ListView
Posted
by i2nfo
on Stack Overflow
See other posts from Stack Overflow
or by i2nfo
Published on 2010-03-24T14:01:20Z
Indexed on
2010/03/24
14:03 UTC
Read the original article
Hit count: 367
Hi
I am currently busy with a WPF application that uses a "GridView".
There are several template columns one of which is a ComboBox in column 3 named cmbInputControlType. What I would like to do using my Converter class, which I have already created, is binding the visibility of the TextBox(txtFrom) in column 4 to the selected value of the ComboBox(Column 3). Basically if you select a value from the the ComboBox(cmbInputControlType - column 3), it must update teh visibility of the TextBox(txtFrom - column 4)
<ListView Height="150" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" Width="435"
HorizontalAlignment="Center" Margin="5,0,5,5"
Name="lstInput" VerticalAlignment="Top"
SelectionMode="Single" HorizontalContentAlignment="Left">
<ListView.Resources>
<local:InputControlTypeConverter x:Key="InputConType" />
</ListView.Resources>
<ListView.View>
<GridView>
<!--Column 1-->
<GridViewColumn Header="ParameterName" x:Name="lblParameterName" DisplayMemberBinding="{Binding ParameterName}" Width="100" />
<!--Column 2-->
<GridViewColumn Header="DisplayName">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="txtDisplayName" Width="150" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!--Column 3-->
<GridViewColumn Header="ControlType">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="cmbInputControlType" Width="100" SelectionChanged="cmbInputControlType_SelectionChanged" >
<ComboBoxItem Content="TextBox" />
<ComboBoxItem Content="Copy" />
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!--Column 4-->
<GridViewColumn Header="From">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="txtCopyFrom" Width="150" Visibility="{Binding ElementName=cmbInputControlType,Path=SelectedItem, Converter={StaticResource InputConType}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!--Column 5-->
<GridViewColumn Header="To">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="txtCopyTo" Width="150" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
© Stack Overflow or respective owner