Некоторое время я работаю над приложением WPF. Несколько недель go Я добавил контекстное меню для кнопки. Назад это было отображено правильно.
Затем я работал над другими областями приложения, не изменяя и даже не используя это контекстное меню.
Теперь я понимаю, что контекстное меню не отображается должным образом. Как вы можете видеть на прилагаемом рисунке, слева есть синяя полоса, которую, я уверен, не было несколько недель go. Я внимательно изучил код, но не могу понять, почему меню отображается неправильно.
Вот XAML кнопки с вложенным контекстным меню:
<!-- NOTE: 1) This Button only contains a context menu and is not
bound to a command itself.
2) An EventTrigger is set up to also open the context
menu on left click.
3) As a ContextMenu isn't part of the VisualTree and
thus the menu items can't be out-of-the-box bound
to commands a BindingProxy (custom class) is used -->
<Button Content="_Manage" Grid.Row="1" Grid.Column="1"
IsEnabled="{Binding IsMenuAllowed}">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="_New"
Command="{Binding Source={StaticResource Proxy},
Path=Data.CmdNew}"/>
<Separator/>
<MenuItem Header="_Rename"
Command="{Binding Source={StaticResource Proxy},
Path=Data.CmdRename}"/>
<MenuItem Header="_Duplicate"
Command="{Binding Source={StaticResource Proxy},
Path=Data.CmdDuplicate}"/>
<Separator/>
<MenuItem Header="Delete"
Command="{Binding Source={StaticResource Proxy},
Path=Data.CmdDelete}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
В App.xaml настроено множество стилей:
<Application.Resources>
<!-- Define the default style for GroupBox -->
<Style TargetType="{x:Type GroupBox}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Height="20" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Define the global style for PasswordBoxes -->
<Style TargetType="{x:Type PasswordBox}">
<Setter Property="Margin" Value="3,0,3,3"/>
<Setter Property="MinWidth" Value="80"/>
<Setter Property="Height" Value="24"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<!-- Define the global style for TextBoxes -->
<Style TargetType="{x:Type TextBox}" >
<Setter Property="Margin" Value="3,0,3,3" />
<Setter Property="MinWidth" Value="80"/>
<Setter Property="Height" Value="24"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Red" />
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors).CurrentItem.ErrorContent}" />
</Trigger>
</Style.Triggers>
</Style>
<!-- Define the default style for the Separator -->
<Style TargetType="{x:Type Separator}">
<Setter Property="Margin" Value="0,6,0,6"/>
</Style>
<!-- Define the default style for StackPanel -->
<Style TargetType="{x:Type StackPanel}">
<Setter Property="Margin" Value="3,6,3,3"/>
</Style>
<!-- Define the default style for Button -->
<Style TargetType="{x:Type Button}">
<Setter Property="Width" Value="70"/>
<Setter Property="Height" Value="24"/>
<Setter Property="Margin" Value="3,0,3,3"/>
</Style>
<!--Define a style for disabled Image Button -->
<Style x:Key="ImageEnabled" TargetType="Image">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.25" />
</Trigger>
</Style.Triggers>
</Style>
<!-- Define the default style for ComboBoxes -->
<Style TargetType="{x:Type ComboBox}">
<Setter Property="MinWidth" Value="80"/>
<Setter Property="Height" Value="24"/>
<Setter Property="Margin" Value="3,0,3,3"/>
</Style>
<!-- Define the default style for Label -->
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0,3,3,0" />
</Style>
<!-- Define the default style for CheckBox -->
<Style TargetType="{x:Type CheckBox}">
<Setter Property="Margin" Value="3,6,3,3" />
</Style>
<!-- Define the default style for Rectangles (Canvas drawing) -->
<Style TargetType="{x:Type Rectangle}">
<Setter Property="Stroke" Value="#6080bc"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
<!-- Define the default style for Lines (Canvas drawing) -->
<Style TargetType="{x:Type Line}">
<Setter Property="Stroke" Value="#6080bc"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
<!-- Define the default style for Path (Canvas drawing) -->
<Style TargetType="{x:Type Path}">
<Setter Property="Stroke" Value="#6080bc"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
</Application.Resources>
У кого-нибудь есть идеи, что может быть причиной проблемы?