how to access control located in listview.view from the code behid file
-
I have a winow contain a list view with code like this
<ListView Grid.Row="1" Name="FilterListView">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Property Name" Width="210">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Name="txtBlock" Visibility="Collapsed" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" >Filter by :</TextBlock>
<ComboBox Name="cmbMatchCondition" Visibility="Visible" Grid.Column="0" Width="50" Margin="1" SelectedIndex="0">
<ComboBoxItem>And</ComboBoxItem>
<ComboBoxItem>Or</ComboBoxItem>
</ComboBox>
</StackPanel>
<ComboBox Name="cmbPropertyName" Grid.Column="1" Margin="1">
</ComboBox>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn><GridViewColumn Header="Condition" Width="150"> <GridViewColumn.CellTemplate> <DataTemplate> <StackPanel> <ComboBox Name="cmbCondition" Margin="1" SelectedIndex="0"> <!--<ComboBoxItem>Equal</ComboBoxItem> <ComboBoxItem>Not Equal</ComboBoxItem>
-
I have a winow contain a list view with code like this
<ListView Grid.Row="1" Name="FilterListView">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Property Name" Width="210">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="55" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Name="txtBlock" Visibility="Collapsed" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" >Filter by :</TextBlock>
<ComboBox Name="cmbMatchCondition" Visibility="Visible" Grid.Column="0" Width="50" Margin="1" SelectedIndex="0">
<ComboBoxItem>And</ComboBoxItem>
<ComboBoxItem>Or</ComboBoxItem>
</ComboBox>
</StackPanel>
<ComboBox Name="cmbPropertyName" Grid.Column="1" Margin="1">
</ComboBox>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn><GridViewColumn Header="Condition" Width="150"> <GridViewColumn.CellTemplate> <DataTemplate> <StackPanel> <ComboBox Name="cmbCondition" Margin="1" SelectedIndex="0"> <!--<ComboBoxItem>Equal</ComboBoxItem> <ComboBoxItem>Not Equal</ComboBoxItem>
First, in order to access any control it must be named. Second, given the visual tree of the txtBlock, it seems you will have to walk that visual tree until you get access to the element you want. I do think you will have to name all of the controls in order to easily facilitate that process. For example, txtBlock is located within a StackPanel that doesn't have a name. Hope this helps.
-
First, in order to access any control it must be named. Second, given the visual tree of the txtBlock, it seems you will have to walk that visual tree until you get access to the element you want. I do think you will have to name all of the controls in order to easily facilitate that process. For example, txtBlock is located within a StackPanel that doesn't have a name. Hope this helps.
Here is another possibility? For txtBlock, hook up a handler for the Loaded event and in the code-behind keep track of TextBlock objects that are passed in as sender parameters. This is what I mean exactly: Your TextBlock definition with Loaded event handler added:
<TextBlock Name="txtBlock" Loaded="txtBlock_Loaded" Visibility="Collapsed" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" >Filter by :</TextBlock>
And add something like this to the code-behind:
Dictionary<int, TextBlock> txtBlockLookup;
int txtBlockCount = 0;private void txtBlock_Loaded(object sender, RoutedEventArgs e)
{
if (txtBlockCount == 0)
{ txtBlockLookup = new Dictionary<int, TextBlock>(); }if (!txtBlockLookup.ContainsKey(txtBlockCount)) { txtBlockLookup.Add(txtBlockCount++, sender as TextBlock); }
}
Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com
modified on Wednesday, March 25, 2009 6:52 PM
-
First, in order to access any control it must be named. Second, given the visual tree of the txtBlock, it seems you will have to walk that visual tree until you get access to the element you want. I do think you will have to name all of the controls in order to easily facilitate that process. For example, txtBlock is located within a StackPanel that doesn't have a name. Hope this helps.
just thanks a lot
You have To Search About The Truth Of Your Life Why Are you Here In Life ?
-
Here is another possibility? For txtBlock, hook up a handler for the Loaded event and in the code-behind keep track of TextBlock objects that are passed in as sender parameters. This is what I mean exactly: Your TextBlock definition with Loaded event handler added:
<TextBlock Name="txtBlock" Loaded="txtBlock_Loaded" Visibility="Collapsed" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" >Filter by :</TextBlock>
And add something like this to the code-behind:
Dictionary<int, TextBlock> txtBlockLookup;
int txtBlockCount = 0;private void txtBlock_Loaded(object sender, RoutedEventArgs e)
{
if (txtBlockCount == 0)
{ txtBlockLookup = new Dictionary<int, TextBlock>(); }if (!txtBlockLookup.ContainsKey(txtBlockCount)) { txtBlockLookup.Add(txtBlockCount++, sender as TextBlock); }
}
Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com
modified on Wednesday, March 25, 2009 6:52 PM
thanks a lot it is a pretty good idea i will try it and tell you what I gain . :)
You have To Search About The Truth Of Your Life Why Are you Here In Life ?