This is a migrated thread and some comments may be shown as answers.

MEF Imported User Controls, Binding TileViewItem Header To Property In User Control

1 Answer 66 Views
TileView
This is a migrated thread and some comments may be shown as answers.
Martyn
Top achievements
Rank 1
Martyn asked on 16 Sep 2011, 11:50 AM
Hello,

I am importing several user controls with MEF into an ObservableCollection<UserControl> in my view model.

I am then binding the ItemsSource of my RadTileView to this ObservableCollection.

I want to set the Header of the tile view item to be bound to a string Property in the imported Views named "Title". I have set the property to NotifyPropertyChanged() when it is set and I have the following DataTemplate for the Tile Header:

<UserControl.Resources>
        <DataTemplate x:Key="ModuleTileHeaderTemplate">
            <TextBlock Text="{Binding Title}"/>
        </DataTemplate>
    </UserControl.Resources>

I have then applied this to the RadTileView like this:

<telerik:RadTileView Name="radTileView1" ItemsSource="{Binding HomeViews}" ItemTemplate="{StaticResource ModuleTileHeaderTemplate}" MinimizedItemsPosition="Top" MaximizeMode="ZeroOrOne">
            <telerik:RadTileView.ItemContainerStyle>
                <Style TargetType="telerik:RadTileViewItem">
                    <Setter Property="MinimizedWidth" Value="100"/>
                </Style>
            </telerik:RadTileView.ItemContainerStyle>
        </telerik:RadTileView>

However, the header of the TileViewItems is still empty.

What am I doing wrong?

Thanks for your help.

Martyn.

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 20 Sep 2011, 11:48 AM
Hello Martyn,
You're experiencing this problem because you're binding the RadTileView to a collection of UIElements(UserControl). When a RadTileViewItem is generated from a binding it checks if the item that comes from this binding is an UIElement and if it's not it sets it as Content and Header, but if the item is an UIElement it is set only as a Content (because an UIElement can not be set in two places in the VisualTree). That's why in the header template you don't have access to the Title property of you UserControl. You can work around this by binding the Title property to the Header property of the RadTileViewItem with a ContainerBinding.
For further information please examine the attached project and if you have more questions feel free to ask.

Regards,
Zarko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TileView
Asked by
Martyn
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Share this question
or