如何在WPF Window.Resources中设置样式.
发布时间:2020-12-14 04:03:00 所属栏目:Windows 来源:网络整理
导读:我想在Window.Resources中创建多个样式.下面是我尝试过的代码,但它不起作用: Window.Resources Style x:Key="StyleOne" TargetType="{x:Type Control}" Setter Property="Control.Background" Value="Blue"/Setter Setter Property="Control.Height" Value=
我想在Window.Resources中创建多个样式.下面是我尝试过的代码,但它不起作用:
<Window.Resources> <Style x:Key="StyleOne" TargetType="{x:Type Control}"> <Setter Property="Control.Background" Value="Blue"></Setter> <Setter Property="Control.Height" Value="20"></Setter> </Style> <Style x:Key="StyleTwo" BasedOn="{StaticResource StyleOne}"> <Setter Property="Control.Background" Value="Red"></Setter> <Setter Property="Control.Height" Value="20"></Setter> </Style> </Window.Resources> <Button Style="{StaticResource StyleOne}"></Button> <Button Style="{StaticResource StyleTwo}"></Button> 它抛出一个错误说:
解决方法
这个错误与样式无关,窗口只能包含一个子节点(设置
Content ),使用一些可以包含多个子节点的容器.例如a
StackPanel 或
Grid .
<StackPanel> <Button .../> <Button .../> </StackPanel> (另见:Panels Overview) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows Socket 最大连接数
- 在Windows Sever2016中搭建DHCP服务为客户机提供ip地址
- .net – WPF中的窗口所有者,并不总是在顶层的行为
- .net – 版本控制Windows COM对象
- 如何将我的dll组织到ASP.NET中bin目录下的多个文件夹中?
- MSDN Windows XP Professional x64 Edition with SP2 +VL简
- .net – Windows窗体应用程序中的富文本
- 如何配置Compass在Windows上生成带有Unix行尾的文件?
- 使用SWAGGER-UI中的Windows身份验证调用WCF
- windows-phone-7 – Windows Phone 7 WebRequest缓存?