Wpf 使所有windows windows开始上传位置默认为CenterScreen

Wpf 使所有windows windows开始上传位置默认为CenterScreen,wpf,xaml,Wpf,Xaml,前几天我问过。现在,我正尝试应用相同的实践来制作我的所有窗口,并将CenterScreen作为默认的WindowsStartUplocation。我试过打字: <Style TargetType="Window"> <Setter Property="WindowStartupLocation"> </Setter> </Style> 但是,WindowsStartUpLocation显然不是此属性的支持属性。是否有一种方法可以

前几天我问过。现在,我正尝试应用相同的实践来制作我的所有窗口,并将CenterScreen作为默认的WindowsStartUplocation。我试过打字:

<Style TargetType="Window">
    <Setter Property="WindowStartupLocation">

    </Setter>
</Style>
但是,WindowsStartUpLocation显然不是此属性的支持属性。是否有一种方法可以实现我所缺少的功能,或者我必须手动更改所有窗口的功能?

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>
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>

虽然这确实满足了我的要求,但在某种程度上,我真正想要的是在我创建新窗口时,默认情况下,WindowsStartUpLocation已经位于CenterScreen。此答案是复制的,粘贴得很差。虽然这确实满足了我的要求,但在某种程度上,我真正想要的是在我创建新窗口时,默认情况下,WindowsStartupLocation已位于CenterScreen。此答案已从中复制并粘贴不好。