Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2165
xamDataTreeContextMenu
posted

Hello,

We need to create an MVVM solution for tree view control with context menu. The context menu has to be different for each node, based on the type of the node.

We have tried the following approach: binding the context menu items to given properties of the XamDataTree's ItemSource.

 

<ig:XamDataTree x:Name="customerGroupTreeView"

                ActiveNodeChanged="customerGroupTreeViewProjects_ActiveNodeChanged"

                ItemsSource="{Binding TreeViewCustomersGroup}"

                BorderThickness="0">

    <ig:XamDataTree.ContextMenu>

        <ContextMenu Loaded="ContextMenu_Loaded">

            <MenuItem Header="New"

                      IsEnabled="{Binding Data.IsNew}">MenuItem>

        ContextMenu>

    ig:XamDataTree.ContextMenu>

    <ig:XamDataTree.EditingSettings>

        <ig:TreeEditingSettings AllowDeletion="{Binding AllowDeletion}"

                                AllowEditing="{Binding AllowEditing}" />

    ig:XamDataTree.EditingSettings>

    <ig:XamDataTree.Resources>

        <DataTemplate x:Key="NodeDataTemplate">

            <Grid>

                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="20">ColumnDefinition>

                    <ColumnDefinition>ColumnDefinition>

                Grid.ColumnDefinitions>

                <Image Grid.Column="0"

                       Height="16"

                       Width="16"

                       Source="{Binding Data.ImagePath}">

                Image>

                <TextBlock Text="{Binding Data.Name}"

                           Margin="5,0,0,0"

                           Grid.Column="1" />

            Grid>

        DataTemplate>

    ig:XamDataTree.Resources>

    <ig:XamDataTree.SelectionSettings>

        <ig:TreeSelectionSettings NodeSelection="Single" />

    ig:XamDataTree.SelectionSettings>

    <ig:XamDataTree.GlobalNodeLayouts>

        <ig:NodeLayout Key="MyNode"

                       TargetTypeName="Node"

                       ItemTemplate="{StaticResource NodeDataTemplate}">

        ig:NodeLayout>

    ig:XamDataTree.GlobalNodeLayouts>

ig:XamDataTree>

 

1. This binding isn't working. Can you please give an example of how the contextmenu would be bound to the Node data?

2. Also, we would like the Node which the user has right clicked on to be the selected node. How can we implement this?

 

Thanks!

DVSE Team

Parents Reply Children
No Data