Astasian
Astasian

Reputation: 429

ItemsControl only shows namespace.class, doesn't render DataTemplate

I have the following problem: In a ItemsControl I have defined some DataTemplates for different classes. For no reason (or maybe I wasn't aware of it), just the class names will be rendered, instead of the Template. When I just use one Template with ItemTemplate and not DataTemplate it'll work. The "Element" classes are internal, a change to public won't do it:

    <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>

Upvotes: 2

Views: 71

Answers (1)

Glen Thomas
Glen Thomas

Reputation: 10744

When referencing a type, use x:Type

So, for your DateFilter DataTemplate:

<DataTemplate DataType="{x:Type local:DateFilter}">

Upvotes: 1

Related Questions