Displaying Inner Controls Content Property as Own [User Control]
I am new to WFP and am trying to learn it with different examples.
Right now, I want to create a custom control that has a button inside (among other controls). I want to show the Content Buttons property as custom controls.
User Control:
<DockPanel LastChildFill="True">
<Button Name="ClickButton" DockPanel.Dock="Right" Focusable="False"/>
<TextBox Name="TextBox">lorem ipsum dolor set amet</TextBox>
</DockPanel>
I want to change the content of buttons in the main application window, for example:
<my:ButtonTextBox Name="mtb1" Grid.Column="0" Grid.Row="0">Some text</my:ButtonTextBox>
There is some text, this is the text that needs to be written above the button ...
How can I achieve this? Thanks!
+2
a source to share
1 answer
UserControl needs to define their own dependency property for the button content:
public static readonly DependencyProperty ButtonContentProperty = ...;
Then bind your UserControl button to this property:
<Button Name="ClickButton" Content="{Binding ButtonContent}" .../>
Then you can use it like this:
<my:ButtonTextBox ButtonContent="Some text" .../>
If you want to do this:
<my:ButtonTextBox ...>Some text</my:ButtonTextBox>
you will need to specify ContentPropertyAttribute on UserControl:
[ContentProperty("ButtonContent")]
public partial class ButtonTextBox
+5
a source to share