Radtreeview使其只在某层节点上显示右键菜单(telerik控件)

<Control.Resources>
        <telerik:RadContextMenu  x:Key="ContextMenu">
            <telerik:RadMenuItem Header="样品清点"  Click="SampleCheck_Click" />
            <telerik:RadMenuItem Header="样品室内描述" Click="SampleStationDes_Click" />
            <telerik:RadMenuItem Header="室内样品" Click="SampleIndoorDescription_Click" />
            <telerik:RadMenuItem Header="添加样品"  Click="AddSample_Click" />
        </telerik:RadContextMenu>
        <DataTemplate x:Key="Station">
            <TextBlock Text="{Binding Name}" Width="120" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </DataTemplate>
        <HierarchicalDataTemplate x:Key="Leg" ItemTemplate="{StaticResource Station}" ItemsSource="{Binding Stations}">
            <TextBlock Text="{Binding Name}"/>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="Voyage" ItemTemplate="{StaticResource Leg}" ItemsSource="{Binding Legs}">
            <TextBlock Text="{Binding Code}"/>
        </HierarchicalDataTemplate>
        <Style x:Key="VoyageItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="DefaultImageSrc" Value="sailing-ship-icon.png"/>
        </Style>
        <Style x:Key="LegItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="DefaultImageSrc" Value="Leg-icon.png"/>
        </Style>
        <Style x:Key="StationItemContainerStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="DefaultImageSrc" Value="Station-icon.png" />
            <Setter Property="telerik:RadContextMenu.ContextMenu" Value="{StaticResource ResourceKey=ContextMenu}" />
            <EventSetter Event="TreeViewItem.PreviewMouseRightButtonDown" Handler="TreeViewItemStation_PreviewMouseRightButtonDown"/>
        </Style>
        <Local:TreeExplorerContainStyleSelector x:Key="myContainerStyleSelector"
                                                VoyageStyle="{StaticResource VoyageItemContainerStyle}"
                                                LegStyle="{StaticResource LegItemContainerStyle}"
                                                StationStyle="{StaticResource StationItemContainerStyle}"/>
    </Control.Resources>
    <Grid>
        <telerik:RadTreeView x:Name="ExplorerTreeView"
                            VerticalAlignment="Stretch"
                            HorizontalAlignment="Stretch"
                            IsRootLinesEnabled="True"
                            MinHeight="200"                            
                            IsLoadOnDemandEnabled="True"
                            ImagesBaseDir="/Images/Icons/"                            
                            BorderBrush="SkyBlue"
                            BorderThickness="2"
                            ItemsSource="{Binding TreeExplorerDataSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                            ItemTemplate="{StaticResource Voyage}"
                            ItemPrepared="ExplorerTreeView_ItemPrepared"                               
                            ItemContainerStyleSelector="{StaticResource myContainerStyleSelector}"
                            LoadOnDemand="ExplorerTreeView_LoadOnDemand">
        </telerik:RadTreeView>
    </Grid>
</UserControl>

 

使用系统自带的contextmenu则需要在treeview上绑定,并在后台控制。

posted @ 2012-10-31 21:22  super 86  阅读(527)  评论(0编辑  收藏  举报