【问题标题】:WPF: Editing ContextMenu or ToolTip in Expression Blend 4: error "cannot have a logical or visual parent."WPF:在 Expression Blend 4 中编辑 ContextMenu 或 ToolTip:错误“不能有逻辑或可视父级”。
【发布时间】:2010-12-28 19:05:25
【问题描述】:

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

  1. 在 EBlend 4 中创建新的 WPF 应用程序。
  2. 将按钮放在窗口上。
  3. 为按钮创建新的 ContextMenu。
  4. 向 ContextMenu 添加两个示例项目(带有标题,即“item1”和“item2”)。
  5. 在“样式”属性下按钮 ContextMenu 属性的“属性”面板中,单击“样式”属性右侧的方块并选择“转换为新资源...”。
  6. 在打开的“创建样式资源”窗口中,为“此文档 [Window:Window]”或新资源字典选择“定义于” - 没关系。
  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>

【问题讨论】:

    标签: wpf contextmenu tooltip blend


    【解决方案1】:

    这是 Microsoft Expression Blend 中的 bug,请查看此链接:"'Tooltip' cannot have a logical or visual parent." when editing style in Blend 4

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 2017-12-17
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多