前几天我问过this question。现在,我正在尝试应用相同的做法来制作我的所有windows
,并CenterScreen
作为默认WindowStartupLocation
。我试着打字:
<Style TargetType="Window">
<Setter Property="WindowStartupLocation">
</Setter>
</Style>
但是,WindowStartupLocation
显然不是支持的属性。有没有办法实现这一点,我缺少,或者我将不得不手动更改所有windows
?
答案 0 :(得分:-1)
的App.xaml
<Application.Resources>
<ResourceDictionary>
<Style x:Key="WindowStyle" TargetType="Window">
<Setter Property="SizeToContent" Value="WidthAndHeight" />
<Setter Property="ResizeMode" Value="CanMinimize" />
</Style>
<WindowStartupLocation x:Key="WSL">CenterOwner</WindowStartupLocation>
</ResourceDictionary>
</Application.Resources>
窗口
<Window x:Class="WpfApplication7.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Width="525" Height="350" WindowStartupLocation="{StaticResource WSL}" Style="{StaticResource WindowStyle}">
<Window.Resources />
<Grid />
</Window>