<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="33" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Title Bar -->
<Grid Height="35" VerticalAlignment="Top" Width="Auto" Name="header" Opacity="0" Background="#EE000000">
</Grid>
<!-- Main Contents -->
<Grid Grid.Row="1" Name="body" Opacity="0" Background="#EE111111">
</Grid>
<Thumb Name="leftThumb" Grid.RowSpan="2" HorizontalAlignment="Left" Width="2" BorderThickness="1.5" BorderBrush="Transparent" Cursor="SizeWE" Opacity="0.5"/>
<Thumb Name="rightThumb" Grid.RowSpan="2" HorizontalAlignment="Right" Width="2" BorderThickness="1.5" BorderBrush="Transparent" Cursor="SizeWE" Opacity="0.5"/>
<Thumb Name="topThumb" Grid.RowSpan="2" VerticalAlignment="Top" Height="2" BorderThickness="1.5" BorderBrush="Transparent" Cursor="SizeNS" Opacity="0.5"/>
<Thumb Name="bottomThumb" Grid.RowSpan="2" VerticalAlignment="Bottom" Height="2" BorderThickness="1.5" BorderBrush="Transparent" Cursor="SizeNS" Opacity="0.5"/>
<ResizeGrip x:Name="WindowResizeGrip" HorizontalAlignment="Right" IsTabStop="false" Visibility="Collapsed" VerticalAlignment="Bottom" Grid.Row="1" />
</Grid>
コードビハインドはこれ。
/// <summary>
/// コンストラクタ
/// </summary>
public MainWindow()
{
InitializeComponent();
// ウィンドウサイズ調整
this.leftThumb.DragDelta += (sender, e) =>
{
this.Left += e.HorizontalChange;
this.Width -= e.HorizontalChange;
};
this.rightThumb.DragDelta += (sender, e) =>
{
this.Width += e.HorizontalChange;
};
this.topThumb.DragDelta += (sender, e) =>
{
this.Top += e.VerticalChange;
this.Height -= e.VerticalChange;
};
this.bottomThumb.DragDelta += (sender, e) =>
{
this.Height += e.VerticalChange;
};
}
/// <summary>
/// ウィンドウ状態変更イベント
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_StateChanged(object sender, System.EventArgs e)
{
if (ResizeMode == System.Windows.ResizeMode.CanResizeWithGrip && WindowState == System.Windows.WindowState.Normal)
{
WindowResizeGrip.Visibility = System.Windows.Visibility.Visible;
}
else
{
WindowResizeGrip.Visibility = System.Windows.Visibility.Collapsed;
}
}
0 件のコメント:
コメントを投稿