wpf 去除window默认样式
程序员文章站
2022-07-13 23:04:15
...
去除window最上面的一行的样式
WindowStyle="None"
添加closing事件 ,可拖拽事件
Height="450" Width="800" Background="#2D2F2F"
WindowStyle="None" ResizeMode="NoResize" MouseLeftButtonDown="Window_MouseLeftButtonDown"
Closing="MainWindow_Closing" WindowStartupLocation="CenterScreen" Foreground="White"
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Current.Shutdown();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
自己添加关闭按钮和标题
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<TextBlock VerticalAlignment="Center" FontSize="20" Margin="20,0,0,0">Restore Tool</TextBlock>
</Grid>
<Grid Grid.Column="1">
<Button Height="49" Width="49" HorizontalAlignment="Right" Click="btnClose_Click">X</Button>
</Grid>
</Grid>
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
上一篇: 多选框