【问题标题】:Make all windows WindowStartupLocation default to CenterScreen使所有窗口 WindowStartupLocation 默认为 CenterScreen
【发布时间】:2013-05-28 14:56:13
【问题描述】:

前几天我问过this question。现在,我正在尝试应用相同的做法来制作我所有的windows,并将CenterScreen 作为默认WindowStartupLocation。我试过打字:

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

    </Setter>
</Style>

但是,WindowStartupLocation 显然不是这个受支持的属性。有没有办法完成我所缺少的这一点,还是我必须为所有 windows 手动更改它?

【问题讨论】:

    标签: wpf xaml


    【解决方案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>
    

    【讨论】:

    • 虽然这确实做了我想要的,但在某种程度上,我真正想要的是当我创建一个新的window 时,WindowStartupLocation 默认已经在CenterScreen .
    • 这个答案是从stackoverflow.com/questions/10596515/… 复制和粘贴的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    相关资源
    最近更新 更多