WPF:在Expression Blend 4中编辑上下文菜单或工具提示:错误“;不能有逻辑或可视父级。”;

WPF:在Expression Blend 4中编辑上下文菜单或工具提示:错误“;不能有逻辑或可视父级。”;,wpf,contextmenu,tooltip,blend,Wpf,Contextmenu,Tooltip,Blend,我想根据Expression Blend 4中的默认设置为ContextMenu或工具提示创建新样式。为此,我执行以下操作(例如ContextMenu): 在eblend4中创建新的WPF应用程序 把按钮放在窗户上 为按钮创建新的上下文菜单 将两个示例项添加到ContextMenu(标题为“item1”和“item2”) 在按钮中的“属性”面板上下文菜单属性属性在“样式”属性下单击“样式”属性右侧的方框,然后选择“转换为新资源…” 在打开的“创建样式资源”窗口中,为“此文档[window:win

我想根据Expression Blend 4中的默认设置为ContextMenu或工具提示创建新样式。为此,我执行以下操作(例如ContextMenu):

  • 在eblend4中创建新的WPF应用程序
  • 把按钮放在窗户上
  • 为按钮创建新的上下文菜单
  • 将两个示例项添加到ContextMenu(标题为“item1”和“item2”)
  • 在按钮中的“属性”面板上下文菜单属性属性在“样式”属性下单击“样式”属性右侧的方框,然后选择“转换为新资源…”
  • 在打开的“创建样式资源”窗口中,为“此文档[window:window]”选择“在中定义”或新资源字典-这无关紧要
  • 我在消息的底部得到了默认样式的XAML上下文菜单,如下所示
  • 我想用预览编辑这个样式,所以我转到“资源”选项卡,找到我的“ContextMenuStyle1”,右键单击并选择“编辑”
  • 我无法编辑样式,有信息表明引发了异常“'ContextMenu'不能具有逻辑或可视父级。”
  • 此外,我也不能向我的资源字典添加任何其他新样式,因为它说“资源不能添加到“ResourceDictionary1.xaml”,因为“ResourceDictionary1.xaml”包含阻止更新的错误。“直到我关闭“ResourceDictionary1.xaml”视图并重新打开它。”

    任何人都能解决这个问题并给出一个解决方案,说明如何在Expression Blend 4中编辑上下文菜单或工具提示样式,并对更改进行可视化预览并访问其所有属性和功能

        <Style x:Key="ContextMenuStyle1" TargetType="{x:Type ContextMenu}">
       <Setter Property="Background" Value="{DynamicResource MenuBackgroundBrush}"/>
       <Setter Property="BorderThickness" Value="1"/>
       <Setter Property="BorderBrush" Value="{DynamicResource WindowBorderBrush}"/>
       <Setter Property="Template">
        <Setter.Value>
         <ControlTemplate TargetType="{x:Type ContextMenu}">
          <Border Uid="Border_93">
           <Border.Style>
            <Style TargetType="{x:Type Border}">
             <Setter Property="Tag" Value="{DynamicResource {x:Static SystemParameters.DropShadowKey}}"/>
             <Style.Triggers>
              <DataTrigger Binding="{Binding Tag, RelativeSource={RelativeSource Self}}" Value="True">
               <Setter Property="Background" Value="Transparent"/>
               <Setter Property="Padding" Value="0,0,5,5"/>
               <Setter Property="Effect">
                <Setter.Value>
                 <DropShadowEffect BlurRadius="4" Opacity="0.8" ShadowDepth="1"/>
                </Setter.Value>
               </Setter>
              </DataTrigger>
             </Style.Triggers>
            </Style>
           </Border.Style>
           <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Uid="Border_50">
            <ScrollViewer CanContentScroll="True" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" Uid="ScrollViewer_9">
             <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Uid="ItemsPresenter_5"/>
            </ScrollViewer>
           </Border>
          </Border>
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>
    

    这是Microsoft Expression Blend中的一个
    bug
    ,请查看以下链接: