微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在WPF中将样式应用于Window Control?

我正在为App.xaml中的Window设置样式,如下所示:
<Application x:Class="MusicRepo_Importer.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" StartupUri="TestMaster.xaml">
    <Application.Resources>

        <Style targettype="Window">
            <Setter Property="WindowStyle" Value="None"></Setter>
        </Style>

    </Application.Resources>
</Application>

我基本上希望每个Window都将其WindowStyle的属性值设置为None(删除认的Windows框架和边框);但它没有用.

在这里想念的是什么?

我相信你必须将样式命名并将其应用于每个窗口,如下所示.

在app.xaml / resources ..

<Style x:Key="MyWindowStyle" targettype="Window">
    <Setter Property="WindowStyle" Value="None"></Setter>
</Style>

然后在window.xaml ..

<Window x:Class="MusicRepo_Importer.MyWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MyStyledWindow" Style="{StaticResource MyWindowStyle}">

这应该可行,但只是在资源中应用具有targettype for Window的样式将不会强制Window使用该样式,尽管它似乎适用于其他元素.

编辑:
找到一些与将认样式应用于窗口元素有关的信息.

If you supply a targettype,all
instances of that type will have the
style applied. However derived types
will not… it seems. <Style
targettype=”{x:Type Window}”> will not
work for all your custom
derivations/windows. <Style
targettype=”{x:Type local:MyWindow}”>
will apply to only MyWindow. So the
options are

Use a Keyed Style that you specify as
the Style property of every window you
want to apply the style. The designer
will show the styled window.

来自问题:How to set default WPF Window Style in app.xaml?

回答问题的人对从具有应用样式的基本窗口继承有一个有趣的想法.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐