I have a user control with this code behind:
/// <summary>
/// The text to use for the header.
/// </summary>
public UIElement HeaderText
{
get { return (UIElement) GetValue(HeaderTextProperty); }
set { SetValue(HeaderTextProperty, value); }
}
public static DependencyProperty HeaderTextProperty =
DependencyProperty.Register("HeaderText",
typeof(UIElement),
typeof(Panel),
new PropertyMetadata(null, new PropertyChangedCallback(HeaderTextPropertyChanged)));
private static void HeaderTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as Panel;
if (control != null)
{
control.HeaderText = (UIElement) e.NewValue;
}
}
And this XAML:
<TextBlock Text="{TemplateBinding local:CustomPanel.HeaderText}" />
And I'm trying to use the user control like this:
<controls:CustomPanel>
<controls:CustomPanel.HeaderText>
<TextBlock Text="Foo " />
<TextBlock Text="{Binding Bar}" />
<TextBlock Text=" baz." />
</controls:CustomPanel.HeaderText>
</controls:CustomPanel>
However, what I get is blank/empty text.
I can get it to work if I change UIElement
into string
in code-behind, but I want to accept both string
, TextBlock
and practically any UIElement
that makes sense for text.
How can I achieve this?