简体   繁体   English

WPF-以编程方式设置TextBox的样式

[英]WPF - Set Style of TextBox programatically

On my XAML i have defined a special style. 在我的XAML我定义了一种特殊的样式。 Here i can access these with my defined resource like: 在这里,我可以使用定义的资源访问这些资源,例如:

<TextBox Style="{StaticResource TransparentInput}" Text="Hello World!" [...] />

But how i can set the Style of an component programatically ? 但是,如何通过编程设置组件的Style

I wan't to add components programatically like 我不会像这样以编程方式添加组件

TextBox test = new TextBox();
test.Text = "Hello World!";
test.Style = [???] //<--- How i set here the static resource "TransparentInput"?

尝试这个:

test.Style = TryFindResource("TransparentInput") as Style;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM