【问题标题】:geting information from Treeview with HierarchicalDataTemplate使用 HierarchicalDataTemplate 从 Treeview 获取信息
【发布时间】:2010-06-01 10:11:11
【问题描述】:

美好的一天!

我有这样一个模板:

 <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> 

对于树形视图

<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>

我想知道 Treeview 中每个 TextBox 的 Name 属性,以便对每个文本框进行验证,例如:

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;
            }
        }

我想看看哪些复选框被选中

我该怎么做?

【问题讨论】:

    标签: silverlight silverlight-3.0 silverlight-toolkit


    【解决方案1】:

    我不确定我是否清楚你为什么需要知道这个名字。

    在这种情况下,LostFocus 事件的sender 参数是有问题的TextBox。因此你可以使用:-

     TextBox tb = (TextBox)sender;
    

    现在使用这个tb 变量而不是使用tbNumber(它实际上并不存在,因为它在模板中定义)。

    【讨论】:

    • 哦!非常感谢您的回答!这正是我需要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多