[WPF]样式未正确应用于堆栈面板中的任何按钮 [英] [WPF] Style is not applied correctly to any button in a stackpanel

查看:94
本文介绍了[WPF]样式未正确应用于堆栈面板中的任何按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在app.xaml中的资源词典中做了这个:

Hi everybody,

I have made this in a resource dictionary istantiated in app.xaml:

<Style TargetType="Button" x:Key="MainButton">
<Setter Property="FontSize" Value="18" />
<!--Other setters omitted-->





和窗口内框架中加载的页面(我把这个代码放在里面)一个Stackpanel.Resources,在stackpanel里面,有两个按钮





and in a page loaded in a frame inside a window (I put this code inside a Stackpanel.Resources and, inside the stackpanel, there are two buttons

<Style BasedOn="{StaticResource MainButton}" TargetType="Button"/>





fontsize中的chages仅在设计器中可见,但在应用程序运行时不可见...



编辑:我省略该页面位于名为Pages的文件夹中。 ...



你们有谁知道这个实现有什么问题吗?



谢谢!



Jymmy097



Chages in fontsize are visible only in the designer, but not when the application is running...

edit: I omitted that the page is inside a folder called Pages....

Does any of you know what is the problem with this implementation?

Thanks!

Jymmy097

推荐答案

我认为问题在于





1.您可以使用DynamicResource而不是StaticResource。

2.缺少双引号所以你可以在Statement的末尾添加双引号并且可以制作



TargetType =按钮





3.做完之后以上所有你可以清理你的解决方案。建立你的解决方案,然后再试一次。
I think problem is with


1.You can use DynamicResource instead of StaticResource.
2.Double Quotes is missing so u can put double quotes at the end of Statement and can make

TargetType="Button"


3.After doing all above you can clean your solution.Rebuild your solution and can then try again.


I think problem is with

<Style BasedOn="{StaticResource MainButton}" TargetType="Button/>

should have

<Style BasedOn="{DynamicResource MainButton}" TargetType="Button"/>


because it might be the case that MainButton style is not available at runtime





You can also try cleaning the solution and Rebuilding it. it might also causes the problem.


这篇关于[WPF]样式未正确应用于堆栈面板中的任何按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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