Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I set the text of a label
    text
    copied!<p>I've got a usercontrol that I want to put in a FixedDocument, but before I do that I need to change the text of a label. I think I need to use Dependency Properties.</p> <p>Here's the simplified XAML.</p> <pre><code>&lt;UserControl x:Class="PrinterTest.TestControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" DataContext="{Binding RelativeSource={RelativeSource Self}}"&gt; &lt;Grid&gt; &lt;Label Content="{Binding LabelCaption}" Height="24" HorizontalContentAlignment="Right" Name="lblCaption" Width="140" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>And the codebehind</p> <pre><code>public partial class TestControl : UserControl { public TestControl() { InitializeComponent(); } public readonly static DependencyProperty LabelCaptionDP = DependencyProperty.Register("LabelCaption", typeof(string), typeof(TestControl), new FrameworkPropertyMetadata("no data")); public string LabelCaption { get { return (string)GetValue(LabelCaptionDP); } set { SetValue(LabelCaptionDP, value); } } </code></pre> <p>In the calling bit I instantiate by <code>TestControl myControl = new TestControl();</code></p> <p>What am I doing wrong, because I can't access the properties in the new copy of the control? Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload