私はこのコードビハインドを持つユーザーコントロールを持っています:
/// <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;
}
}
そして、この XAML:
<TextBlock Text="{TemplateBinding local:CustomPanel.HeaderText}" />
そして、私は次のようにユーザーコントロールを使用しようとしています:
<controls:CustomPanel>
<controls:CustomPanel.HeaderText>
<TextBlock Text="Foo " />
<TextBlock Text="{Binding Bar}" />
<TextBlock Text=" baz." />
</controls:CustomPanel.HeaderText>
</controls:CustomPanel>
ただし、空白/空のテキストが表示されます。
コードビハインドに変更すれば動作させることができますがUIElement
、両方を受け入れたいと思っています。string
string
TextBlock
UIElement
どうすればこれを達成できますか?