사용자 지정 스타일을 지원하는 MenuItems가있는 WPF ContextMenu가 있습니다. MenuItem은 ToggleButton입니다. ToggleButton이 선택되면 텍스트 상자와 닫기 버튼이있는 팝업이 나타납니다.팝업 텍스트 상자가있는 MenuItem
<Style TargetType="MenuItem">
<Setter Property="Foreground" Value="{StaticResource ForegroundColor}"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem" >
<Grid>
<Border Name="Border" Height="25"
Background="{StaticResource BackgroundColor}">
<ToggleButton Name="tbtnOpenPopup">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Name="externalBorder" Background="Transparent"
BorderThickness="0">
<ContentPresenter Content="{TemplateBinding Content}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="externalBorder" Property = "Background" Value="{StaticResource DropDownHighlightedBackgroundColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="7"/>
</Grid.ColumnDefinitions>
<ContentPresenter ContentSource="Header" VerticalAlignment="Center"
Margin="10,0,0,0"/>
<Path Name="Arrow" Grid.Column="1"
Data="M0,3 L5,0 L0,-3 L0,3 Z"
Fill="{TemplateBinding Foreground}"
VerticalAlignment="Center"/>
</Grid>
</ToggleButton>
</Border>
<Popup Grid.ColumnSpan="2"
Name="Popup"
Placement="Right"
AllowsTransparency="True"
Focusable="False"
StaysOpen="True"
IsOpen="False"
PopupAnimation="None">
<Grid Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="22"/>
</Grid.ColumnDefinitions>
<Border MinHeight="25" Grid.ColumnSpan="2"
x:Name="DropDownBorder"
Background="{StaticResource DropDownBackgroundColor}"
BorderThickness="0"/>
<TextBlock Text="Some text" VerticalAlignment="Top"
HorizontalAlignment="Stretch"/>
<Button Name="closeButton"
Content="X"
Grid.Column="1"
VerticalAlignment="Top"
HorizontalAlignment="Right"/>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="tbtnOpenPopup" Property="IsChecked" Value="true">
<Setter TargetName="Popup" Property="IsOpen" Value="true"/>
<Setter TargetName="Arrow" Property="Data" Value="M5,3 L0,0 L5,-3 L5,3 Z"/>
</Trigger>
<Trigger SourceName="closeButton" Property="IsPressed" Value="true">
<Setter TargetName="tbtnOpenPopup" Property="IsChecked" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
는 내가 "closeButton으로는"누르면 팝업 텍스트 상자를 닫으려면, 오픈 숙박에의 ContextMenu. 그러나 "closeButton"을 누르면 ContextMenu가 닫힙니다.
나는 그것이 왜 일어나고 있는지 이해할 수 없었다.
아이디어가 있습니까?