ContentControl から派生した新しいカスタム コントロール (ウィンドウ内の他のコントロールのコンテナーになります) を作成したいのですが、それを閉じるボタンが必要です。(実際、ボーダーレスウィンドウが必要ですが、システムのようなボタンで閉じることができます)。
そこで、2 つの行を持つ Grid を含むコントロールのスタイルを作成しました。上の行には、1 つのボタンを持つ StackPanel があります。
ボタンの Click イベントをコントロール自体にバインドしたり、イベントを発生させたり、Close コマンドを親ウィンドウに送信したりするにはどうすればよいですか?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
<Border Background="Azure" Grid.Row="0">
<StackPanel Orientation="Horizontal">
<Button HorizontalAlignment="Right" Content="X" Click="Close_Click" />
</StackPanel>
</Border>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"/>
</Grid>
そして背後にあるコード:
static STContentControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(STContentControl), new FrameworkPropertyMetadata(typeof(STContentControl)));
}
public void Close_Click(object sender, RoutedEventArgs ea)
{
}