我有以下问题:
在ItemsControl
中,我为不同的类定义了一些DataTemplates
。无缘无故(或者我可能没有意识到),只会呈现类名,而不是模板。当我只使用一个带有ItemTemplate
而不是DataTemplate
的模板时,它会起作用。 “元素”类是内部的,对公众的改变不会这样做:
<ItemsControl ItemsSource="{Binding FilterElements}" >
<ItemsControl.Resources>
<DataTemplate DataType="local:DateFilter">
<StackPanel Orientation="Horizontal" MaxHeight="35">
<Label Content="From " VerticalAlignment="Center" />
<DatePicker SelectedDate="{Binding StartDate}" MaxWidth="120" BorderThickness="0"
VerticalAlignment="Center" />
<Label Content=" to " VerticalAlignment="Center" />
<DatePicker SelectedDate="{Binding EndDate}" MaxWidth="120" BorderThickness="0"
VerticalAlignment="Center" />
<local:IconButton Icon="Resources/x-8x.png" Margin="0" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="local:TimeFilter">
<StackPanel Orientation="Horizontal" MaxHeight="35">
<Label Content="Timespan: " VerticalAlignment="Center" />
<xctk:TimePicker StartTime="{Binding StartTime}" EndTime="{Binding EndTime}"
MaxWidth="120" BorderThickness="0"
VerticalAlignment="Center" />
<local:IconButton Icon="Resources/x-8x.png" Margin="0" />
</StackPanel>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
答案 0 :(得分:1)
引用类型时,请使用x:Type
所以,对于你的DateFilter DataTemplate:
<DataTemplate DataType="{x:Type local:DateFilter}">