要点:
IsSharedSizeScope
属性
<Window x:Class="Grid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Grid"
mc:Ignorable="d"
Title="MainWindow" Height="250" Width="300">
<Grid Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition/>
Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" SharedSizeGroup="A" />
<ColumnDefinition Width="100" SharedSizeGroup="B"/>
<ColumnDefinition/>
Grid.ColumnDefinitions>
<Border Background="Orange"/>
<Border Background="Green" Grid.Column="1" Margin="3,7,10,15"/>
<GridSplitter HorizontalAlignment="Right" Height="10" Width="5" Background="Gray"/>
<GridSplitter HorizontalAlignment="Right" Height="10" Width="5" Background="Gray" Grid.Column="1"/>
Grid>
<Grid Grid.Row="1" Height="60" VerticalAlignment="Top" Margin="0,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A"/>
<ColumnDefinition SharedSizeGroup="B"/>
<ColumnDefinition/>
Grid.ColumnDefinitions>
<Border Background="Orange">
Border>
<Border Grid.Column="1" BorderBrush="Red" BorderThickness="1">
<TextBlock/>
Border>
Grid>
Grid>
Window>
如果Window的WindowStyle=“None”,则Window会没有边框,此时无法拖动窗口,并且也没有最大最小和关闭按键。同时设置AllowsTransparency="True"和Background=“Transparent”。
此时可以使用WindowChrome来解决
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="50" UseAeroCaptionButtons="False"/>
WindowChrome.WindowChrome>
注意:
如果某个控件位于CaptionHeight设定的高度内,是不能被命中的,解决办法是在该控件内添加属性WindowChrome.IsHitTestVisibleInChrome="True"
<Window.Clip>
<PathGeometry Figures="M0,0 200,0A75 75 0 0 1 200 150L0,150z"/>
Window.Clip>
表示将图形之外的内容都裁剪掉
AllowsTransparency="True" WindowStyle="None"
使用WindowChrome
一起使用,因为给裁剪了MouseLeftButtonDown
事件private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}