如何分配在代码中动态资源的风格? [英] How to assign a dynamic resource style in code?

查看:86
本文介绍了如何分配在代码中动态资源的风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在代码中产生这XAML等价的:

 < TextBlock的
文本=标题:
WIDTH ={结合FormLabelColumnWidth}
风格={DynamicResource FormLabelStyle}/>



我可以做文字和宽度,但我怎么分配动态资源的样式:

 的TextBlock TB =新的TextBlock(); 
tb.Text =标题:;
tb.Width = FormLabelColumnWidth;
tb.Style =?


解决方案

您可以试试:

  tb.Style =(风格)FindResource(FormLabelStyle); 



享受!


I want to produce in code the equivalent of this in XAML:

<TextBlock
Text="Title:"
Width="{Binding FormLabelColumnWidth}"
Style="{DynamicResource FormLabelStyle}"/>

I can do the text and the width, but how do I assign the dynamic resource to the style:

TextBlock tb = new TextBlock();
            tb.Text = "Title:";
            tb.Width = FormLabelColumnWidth;
            tb.Style = ???

解决方案

You can try:

tb.Style = (Style)FindResource("FormLabelStyle");

Enjoy!

这篇关于如何分配在代码中动态资源的风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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