views:

101

answers:

1

Good day!

I have such a template:

 <common:HierarchicalDataTemplate x:Key="my2ndPlusHierarchicalTemplate" ItemsSource="{Binding Children}">
                    <StackPanel Margin="0,2,5,2" Orientation="Vertical" Grid.Column="2">
                        <CheckBox
                        IsTabStop="False"
                        IsChecked="False"
                        Click="ItemCheckbox_Click"
                        Grid.Column="1"
                        />
                        <TextBlock Text="{Binding Name}" FontSize="16"  Foreground="#FF100101" HorizontalAlignment="Left" FontFamily="Verdana" FontWeight="Bold" />
                        <TextBlock Text="{Binding Description}" FontFamily="Verdana" FontSize="10" HorizontalAlignment="Left"  Foreground="#FFA09A9A" FontStyle="Italic" />    

<TextBox Width="100" Grid.Column="4" Height="24" LostFocus="TextBox_LostFocus" Name="tbNumber"></TextBox>

</StackPanel>
        </common:HierarchicalDataTemplate> 

for a Treeview

<controls:TreeView x:Name="tvServices" ItemTemplate="{StaticResource myHierarchicalTemplate}" ItemContainerStyle="{StaticResource expandedTreeViewItemStyle}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="3" BorderBrush="#FFC1BCBC" FontFamily="Verdana" FontSize="14">                       
        </controls:TreeView>

I want to know the Name property of each TextBox in Treeview to make validation of each textbox such as:

private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            tbNumber.ClearValidationError();
            if ((!tbNumber.Text.IsZakazNumberValid()) && (tbNumber.Text != ""))
            {
                tbNumber.SetValidation(MyStrings.NumberError);
                tbNumber.RaiseValidationError();
                isValid = false;
            }
            else
            {
                isValid = true;
            }
        }

and I wnat to see what check boxes were checked

how can I do it?

A: 

I'm not sure I'm clear why you need to know the name.

In this case the sender parameter of the LostFocus event is the TextBox in question. Hence you could use:-

 TextBox tb = (TextBox)sender;

Now use this tb variable instead of using tbNumber (which doesn't actually exist because its defined in a template).

AnthonyWJones
oh! thank you very much for your answer! it'a exactly what i need!
lina