【问题标题】:WPF and OxyPlot: Checkable ContextMenu, dynamically generatedWPF 和 OxyPlot:可检查的 ContextMenu,动态生成
【发布时间】:2015-08-14 16:30:27
【问题描述】:

我有一个带有 OxyPlot 视图的 WPF 窗口。我正在尝试根据情节的动态生成、可检查的上下文菜单添加每个系列的隐藏/显示功能。 这个想法是有一个ObservableCollection<T> 对象,绑定到上下文菜单的ItemsSource,其中 T 是一个基本上包含系列标题为字符串和默认检查状态为布尔值的类。

View.xaml 的摘录:

<oxy:PlotView
    x:Name="oxyPlot"
    Model="{Binding PlansPlotModel}"
    Controller="{Binding PlansPlotController}">

    <oxy:PlotView.ContextMenu>
        <ContextMenu ItemsSource="{Binding PlansPlotContextMenuItems}">
            <ContextMenu.ItemTemplate>
                <DataTemplate>
                    <MenuItem Header="{Binding Title}"
                              IsCheckable="True"
                              IsChecked="{Binding IsCheckedByDefault}" />
                </DataTemplate> 
            </ContextMenu.ItemTemplate>
        </ContextMenu>
    </oxy:PlotView.ContextMenu>
</oxy:PlotView>

上下文菜单显示正确,但复选框位置错误,鼠标悬停时出现奇怪行为:

预期结果:

实际结果:

我错过了什么?

TIA

【问题讨论】:

    标签: c# wpf oxyplot


    【解决方案1】:

    使用 ItemContainerStyle 代替:

    <ContextMenu.ItemContainerStyle>
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="IsChecked" Value="{Binding IsCheckedByDefault}"/>
            <Setter Property="IsCheckable" Value="true"/>
            <Setter Property="Header" Value="{Binding Title}"/>
        </Style>
    </ContextMenu.ItemContainerStyle>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2012-10-15
      • 1970-01-01
      相关资源
      最近更新 更多