私はWPFウィンドウを元に戻しました。ただし、タイトルバーをクリックしたときにポップアップメニューを表示する必要があります。私はタイトルのクリックがスタイルの枠線の一つでマウスによって処理され、これは私がいくつかのウィンドウに適用している一般的なスタイルであるので、これをどうやって行うことができないのか分かりません。ClickイベントをカスタムWPF WindowTitleに追加する方法
は、ウィンドウスタイルは次のようになります。次のように
partial class MYStyles
{
public void HandleTitleBarMouseDown(object sender, MouseButtonEventArgs e)
{
Window window = GetWindow(sender);
window.DragMove();
}
}
私はスタイルを再利用:
<Window x:Class="TestWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:TestWPF"
Style="{DynamicResource MYWindow}" Title="Test MY Window" Height="599" Width="891" SnapsToDevicePixels="False" WindowStyle="None" Padding="0" MouseDown="">
次のように
<Style x:Key="MYWindow" TargetType="{x:Type Window}">
<Setter Property="ResizeMode" Value="NoResize" />
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Background" Value="{StaticResource BGBrush}" />
<Setter Property="Foreground" Value="{StaticResource FGBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="26"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="26"/>
<ColumnDefinition Width="26"/>
<ColumnDefinition Width="26"/>
</Grid.ColumnDefinitions>
<Border Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="{x:Null}" CornerRadius="5,5,5,5" BitmapEffect="{StaticResource DropShadow}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Grid.ColumnSpan="4"/>
<ContentPresenter Margin="2" ClipToBounds="True" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"/>
<Border Background="{StaticResource GreyGradientBrush}" BorderThickness="1" BorderBrush="{x:Null}" CornerRadius="5,5,0,0" BitmapEffect="{StaticResource WindowTitleShadow}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" MouseDown="HandleTitleBarMouseDown"/>
現在HandleTitleBarMouseDownは、ウィンドウのドラッグを処理します
私は何とかWindow1クラスでイベントを発生させる必要がありますが、どのように実現するかはわかりませんこれは?