1
我無法弄清楚我在這裏失蹤的內容。我想將ContentPresenter的內容綁定到UIElement。我在做這樣的事情:無法綁定contentPresenter的內容
<Window.Resources>
<DataTemplate x:Key="container">
<Border>
<!--<TextBlock Text="A"/>-->
<ContentPresenter Content="{Binding Element}" />
</Border>
</DataTemplate>
</Window.Resources>
<ContentControl DataContext="{Binding}" ContentTemplate="{StaticResource container}" />
在MainWindow.cs
UIElement Element { get; set; }
public MainWindow()
{
Element = new TextBox() { Text = "A" };
DataContext = this;
InitializeComponent();
}
我可以把文本塊直接,但是當我嘗試ContentPresenter它不會顯示任何內容。
好吧!第一個問題是「元素」不公開。第二個問題是ContentControl沒有「內容」,因此ContentTemplate沒有內容可以使用該模板。 – Scott