DynamicResource and Dynamic Items in ContextMenu on XamDataGrid

Posted by miguel on Stack Overflow See other posts from Stack Overflow or by miguel
Published on 2010-04-15T10:50:22Z Indexed on 2010/04/15 10:53 UTC
Read the original article Hit count: 1085

Filed under:
|
|
|

I would like to dynamically create a set of context menu options based upon some properties.

Currently, I am creating a context menu as a DynamicResource with the visibility of the menu options bound to the properties, however, it seems that the DynamicResource is created only once, at runtime. Is this true? What I would like to do is have the menu generated each time, which will take into account the property changes on the data object.

Please see the following XAML snippet:

<Border DockPanel.Dock="Right"  Margin="4,4,4,4" BorderBrush="Gray" BorderThickness="1" CornerRadius="3" >
        <igDP:XamDataGrid Height="Auto" Width="Auto" Style="{DynamicResource DefaultInfragisticsGridStyle}" Name="axeDataGrid" ActiveRecord="{Binding Path=SelectedItem, Mode=TwoWay}"  DataSource="{Binding Path=Axes}" ContextMenuOpening="ContextMenuOpeningHandler">
            <igDP:XamDataGrid.Resources>
                <Style TargetType="{x:Type igDP:DataRecordPresenter}" BasedOn="{x:Static Themes:DataPresenterAero.DataRecordPresenter}"/>
                <ContextMenu x:Key="RecordContextMenu">
                    <ContextMenu.Resources>
                        <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
                    </ContextMenu.Resources>
                    <MenuItem Header="Cancel Axe"

                              Command="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                        AncestorType={x:Type igDP:XamDataGrid}}, 
                                                        Path=DataContext.CancelAxe}"
                              Visibility="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                        AncestorType={x:Type igDP:XamDataGrid}}, 
                                                        Path=DataContext.IsCancelAxeAllowed, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"/>
                    <MenuItem Header="Create RFQ"

                              Command="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                        AncestorType={x:Type igDP:XamDataGrid}}, 
                                                        Path=DataContext.CreateRFQ}"
                              Visibility="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                        AncestorType={x:Type igDP:XamDataGrid}}, 
                                                        Path=DataContext.IsCreateRfqAllowed, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"/>

                </ContextMenu>
                <Style TargetType="{x:Type igDP:DataRecordCellArea}">
                    <Setter Property="ContextMenu" Value="{DynamicResource RecordContextMenu}" />

                </Style>

© Stack Overflow or respective owner

Related posts about xaml

Related posts about xamdatagrid