1

我想根据 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>
4

1 回答 1

0

那是bug在 Microsoft Expression Blend 中查看此链接:“'Tooltip' 不能有逻辑或视觉父级。” 在 Blend 4 中编辑样式时

于 2011-10-20T18:07:47.240 回答