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

发布于 2024-10-09 08:17:45 字数 2833 浏览 0 评论 0原文

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

  1. 在 EBlend 4 中创建新的 WPF 应用程序。
  2. 将按钮放在窗口上。
  3. 为按钮创建新的上下文菜单。
  4. 将两个示例项目添加到 ContextMenu(带有标题,即“item1”和“item2”)。
  5. 在“属性”面板中,在“样式”属性下的按钮 ContextMenu 属性属性中,单击“样式”属性右侧的方块,然后选择“转换为新资源...”。
  6. 在打开的“创建样式资源”窗口中,为“此文档[窗口:窗口]”选择“定义于”或新的资源字典 - 没关系。
  7. 我在消息底部得到了 ContextMenu 默认样式的 XAML,如下所示。
  8. 我想通过预览编辑此样式,因此我转到“资源”选项卡,找到“ContextMenuStyle1”,右键单击并选择“编辑”。
  9. 我无法编辑样式,有信息抛出异常“'ContextMenu'不能有逻辑或视觉父级。”。

此外,我也无法向我的资源字典添加任何其他新样式,因为它显示“无法将资源添加到“ResourceDictionary1.xaml”,因为“ResourceDictionary1.xaml”包含阻止其更新的错误。”直到我关闭“ResourceDictionary1.xaml”视图并重新打开它。

任何人都可以解决这个问题并给出如何在 Expression Blend 4 中编辑 ContextMenu 或 ToolTip 样式并提供更改的可视化预览并访问其所有属性和功能的解决方案吗?

    <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>

I want to create new style for ContextMenu or Tooltip basing on it's defaults in Expression Blend 4. To do this I do the following (example for ContextMenu):

  1. Create new WPF application in EBlend 4.
  2. Put button on window.
  3. Create new ContextMenu for button.
  4. Add two example items to ContextMenu (with header i.e. "item1" and "item2").
  5. In "Properties" panel in buttons ContextMenu property properties under "Style" property click on the square on right side of "Style" property and choose "Convert to new resource...".
  6. In opened "Create style resource" window choose "defined in" for "This document [Window:Window]" or new Resource dictionary - it doesn't matter.
  7. I get XAML for default style of ContextMenu like this in the bottom of my message.
  8. I want to edit this style with preview, so I go to "Resources" tab, find my "ContextMenuStyle1", right click and choose "Edit".
  9. I cannot edit the style, have information that an Exception was thrown "'ContextMenu' cannot have a logical or visual parent.".

Additionally I cannot also add to my resource dictionary any other new styles, because it says "The resource cannot be added to "ResourceDictionary1.xaml", since "ResourceDictionary1.xaml" contains errors which prevent it of being updated." until I close "ResourceDictionary1.xaml" view and reopen it.

Can anybody solve the problem and give a solution on how to edit ContextMenu or ToolTip style in Expression Blend 4 with visual preview of changes and access to all it's properties and features?

    <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满身野味 2024-10-16 08:17:45

这是 Microsoft Expression Blend 中的一个 bug,请查看此链接:"'工具提示'不能有逻辑或视觉父级。"在 Blend 4 中编辑样式时

That's a bug in Microsoft Expression Blend look at this link: "'Tooltip' cannot have a logical or visual parent." when editing style in Blend 4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文