WPF: Editing ContextMenu or ToolTip in Expression Blend 4: error "cannot have a logical or visual parent."
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):
- Create new WPF application in EBlend 4.
- Put button on window.
- Create new ContextMenu for button.
- Add two example items to ContextMenu (with header i.e. "item1" and "item2").
- 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...".
- In opened "Create style resource" window choose "defined in" for "This document [Window:Window]" or new Resource dictionary - it doesn't matter.
- I get XAML for default style of ContextMenu like this in the bottom of my message.
- I want to edit this style with preview, so I go to "Resources" tab, find my "ContextMenuStyle1", right click and choose "Edit".
- 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 U开发者_C百科id="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>
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
精彩评论