加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 04:11:57 所属栏目:Windows 来源:网络整理
导读:我正在为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
我正在为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?

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读