WPF UserControl exposing style?
How do I expose a style as a property in a WPF USER CONTROL ?
I have a user control that has a textbox. Let's called this textbox "mainTextBox". Let's call my control "myControl".
I want the user of the control to be able to do something like :
<myControl ma开发者_开发问答inTextBoxStyle={StaticResource someStyle} >
How do I do this and is it even possible ?
Regards, Sebastian
Add a dependency property MainTextBoxStyle
to your UserControl
that is of the type Style
.
In the constructor of your UserControl
create a Binding from 'MainTextBoxStyle' to the Style
-property of the TextBox
.
Here an example for the binding:
mainTextBox.SetBinding(TextBox.StyleProperty,new Binding("MainTextBoxStyle"){Source=this,Mode=TwoWay});
精彩评论