如果我有一个DataTemplate(或类似的东西),我可以在画布中使用非UIElements吗?我觉得我以前做过这件事,而且这是可能的,但我无法弄清楚。下面是一些代码...WPF画布项目和DataTemplate
<Window x:Class="EntityTranslator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:EntityTranslator"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Entity x:Key="DesignEntity}" EntityName="Test" />
<DataTemplate DataType="{x:Type local:Entity}">
<StackPanel>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<Canvas>
<local:Entity EntityName="Test" />
</Canvas>
</Grid>
</Window>
有你的尝试过吗? 我没有看到为什么这不应该工作 –
@eranotzer当然我试过了,这是代码,抱怨'本地:实体'不是一个UIElement,这是帆布的期望。 –