资源字典中的窗口启动位置 [英] Window Startup Location from resource dictionary

查看:48
本文介绍了资源字典中的窗口启动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将所有窗口设置为在屏幕中央打开.我所有的窗口都使用样式文件:

I'm trying to set all my windows to open in the center of the screen. All my windows use style file:

    <Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Styles/Mystyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

所以我只是将这个属性插入到资源字典中:

So I just inserted this property to the resource dictionary:

    <Style x:Key="windowStyle" TargetType="Window">
         <Setter Property="WindowStartupLocation" Value="CenterScreen"/>
    </Style> 

但是,它不起作用.我错过了什么吗?

But, it doesn't work. Am I missing something?

推荐答案

您不能使用 Style 来定义 WindowStartupLocation,这是因为它不是依赖属性.您可以在您的资源字典中定义一个静态资源,您将在您的窗口中使用它:

You cannot use a Style to define WindowStartupLocation, this is due to the fact that it is not a dependency property. You can define a StaticResource in your resource dictionary which you will use in your windows:

<WindowStartupLocation x:Key="StartupLocation">CenterScreen</WindowStartupLocation>

然后像这样使用它:

WindowStartupLocation="{DynamicResource StartupLocation}"

这篇关于资源字典中的窗口启动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆