<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 areUse 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?
回答问题的人对从具有应用样式的基本窗口继承有一个有趣的想法.