绑定到menuitem的DataContext不起作用

时间:2015-05-13 14:38:12

标签: c# wpf menuitem

我试图通过在contextmenu中设置datacontext来将checkite和unchecked的menuitem绑定到属性。它不起作用。谢谢你

        <xcdg:DataGridControl Name="DataGrid" 
                          x:Uid="ExtendedDataGrid" 
                          AutomationProperties.AutomationId="ExtendedDataGrid" 
                          SelectionChanged="DataGrid_OnSelectionChanged"
                          VirtualizingStackPanel.VirtualizationMode="Recycling" 
                          Margin="0,0,0,0" 
                          Loaded="DataGrid_OnLoaded"
                          NavigationBehavior="RowOnly"
                          AutoCreateColumns="False"
                          ItemsSource="{Binding ElementName=DataGridContainer, Path=Measurements}">
<ContextMenu x:Key="StatisticsFunctionContextMenu" x:Uid="DataGridStatisticsFunctionContextMenu" AutomationProperties.AutomationId="DataGridStatisticsFunctionContextMenu" DataContext="{Binding ElementName=DataGridContainer, Path=StatsViewModel}">
    <MenuItem Name="StatisticsFunctions" Header="{x:Static Properties:Resources.StatisticsFunctionsMenu}" x:Uid="DataGridStatisticsFunctionContextMenu_StatisticsFunctions" AutomationProperties.AutomationId="DataGridStatisticsFunctionContextMenu_StatisticsFunctions">
        <MenuItem.Icon>
            <Image MaxWidth="16" MaxHeight="16" Source="pack://application:,,,/AnalysisView;component/Images/StatisticsFunctions.png"></Image>
        </MenuItem.Icon>
    <MenuItem Name = "StatisticsFunctionsShowMenu" IsCheckable="True" IsChecked="{Binding Path=StatisticsFunctionsSetting.IsShowChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Command = "commonview:ApplicationCommands.ShowStatisticsFunctions" Header="{x:Static Properties:Resources.StatisticsFunctionsShowMenu}" />
    </MenuItem>
</ContextMenu>
            <!-- STYLE: DataRow -->
            <Style TargetType="{x:Type xcdg:DataRow}" BasedOn="{StaticResource ZetasizerTableflowViewClassicSystemColorDataRowStyle}">
              <Style.Resources>
                <Style TargetType="xcdg:HierarchicalGroupLevelIndicatorPane">
                  <Setter Property="Template" Value="{StaticResource ZetasizerTableflowViewHierarchicalGroupLevelIndicatorPaneTemplate}"/>
                </Style>
                <Style TargetType="{x:Type xcdg:DataCell}" BasedOn="{StaticResource ZetasizerTableflowViewClassicSystemColorDataCellStyle}">
                    <Setter Property="ContextMenu" Value="{Binding Source={StaticResource StatisticsFunctionContextMenu} }" />
                </Style>
              </Style.Resources>
          </Style>

输出窗口中的错误消息:

  

System.Windows.Data错误:4:找不到绑定源   引用'ElementName = DataGridContainer'。   BindingExpression:路径= StatsViewModel;的DataItem = NULL;目标要素   是'ContextMenu'(Name =''); target属性是'DataContext'(类型   '对象')

0 个答案:

没有答案