【问题标题】:TreeView doesn't have the AfterExpand event?TreeView 没有 AfterExpand 事件?
【发布时间】:2011-12-04 22:34:01
【问题描述】:

我尝试使用一个树视图来浏览潜在的循环分层数据。 这意味着我不能尝试一次加载所有树,因为那时可能存在无限循环。

我想对记录在 here at MSDN 的 TreeView.AfterCollapse 事件作出反应

但是,我的控件似乎没有这个事件。如果我尝试添加 AfterExpand 属性,我会收到以下错误消息:

 error MC3072: The property 'AfterExpand' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. Line 23 Position 21.

我做错了什么?调用错误的命名空间? 代码如下:

<Window x:Class="MyApp.Edit.EditView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyApp.Edit"
    Title="{Binding WindowTitle,UpdateSourceTrigger=PropertyChanged}" MinHeight="350" MinWidth="350">

    <Window.Resources>
        <HierarchicalDataTemplate x:Key="sectionTemplate"
        ItemsSource="{Binding ChildSections}"
        DataType="{x:Type local:Section}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Label, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock Text=" - " />
                <TextBlock Text="{Binding Description}" FontStyle="Italic" Foreground="#777" />
            </StackPanel>
        </HierarchicalDataTemplate>
    </Window.Resources>

    <StackPanel>

    <TreeView ItemsSource="{Binding Sections}"
                SelectedItemChanged="TreeView_SelectedItemChanged"
                ItemTemplate="{StaticResource sectionTemplate}"
                MinHeight="150"
                MinWidth="300"
                Name="treeView"
                AfterExpand="MyEventHandler"
        </TreeView>

        <TextBox Text="{Binding Label, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 Margin="0 10 0 0"/>

        <TextBox Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 Margin="0 10 0 0"/>

        <StackPanel Orientation="Horizontal">
            <Button Content="Add Child" Click="Button_Click_AddChild" />
        </StackPanel>
    </StackPanel>
</Window>

【问题讨论】:

  • 我认为它在 wpf 中不可用。

标签: c# .net wpf xaml treeview


【解决方案1】:

这是一个Windows Forms树视图事件,它不属于WPFTreeView,在WPF中可以使用TreeViewItemsCollapsedExpanded,而不是TreeView本身。

但是,您可以订阅 TreeView 上的事件,因为它们是 routed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 2017-02-09
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多