I’ve created a user control that is a Button with a TextBlock and an Image assigned to it:
<UserControl x:Class="App_Designer.Resources.ucDropDownButton" ... />
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top" Margin="10">
<Button x:Name="ButtonDropDown">
<StackPanel Orientation="Horizontal">
<Image Name="imgButton" Margin="0,0,5,0" VerticalAlignment="Center" x:FieldModifier="public"></Image>
<TextBlock Name="txtButtonContent" x:FieldModifier="public"></TextBlock>
</StackPanel>
</Button>
If I reference it on my page:
<local:ucDropDownButton x:Name="btnAddImportTemplate" />
How do I set the contents of the txtButtonContent TextBlock in the XAML? I assumed I’d be able to write :
<local:ucDropDownButton x:Name="btnAddImportTemplate" txtButtonContent.Text="whatever" />
I know I can do it in code with btnAddImportTemplate.txtButtonContent.Text = "whatever";
but I’d like to be able to set it in the XAML itself. I added the x:FieldModifier after researching the issue but that hasn’t helped.
You should add a public property onto the User Control class
MyText will now be possible to set from XAML