简体   繁体   中英

WPF - Set Style of TextBox programatically

On my XAML i have defined a special style. 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 ?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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