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

RadTileViewItem not the source of TileStateChanged event

9 Answers 262 Views
TileView
This is a migrated thread and some comments may be shown as answers.
kilhoffer
Top achievements
Rank 1
kilhoffer asked on 09 Jul 2010, 09:48 PM
In many examples, I see the use of the TileStateChanged event to manually control the tile state. In every example, the first line of code in the event handler is this:

RadTileViewItem item = e.Source as RadTileViewItem;

But when use the same code in my own handler, the e.Source reference is to the RadTileView, not RadTileViewItem. Just to note, I'm wiring the event up in xaml using the following:

<my:RadTileView x:Name="ClassOverridesTileView" 
                        ItemsSource="{Binding Classes}" 
                        ItemTemplate="{StaticResource HeaderTemplate}"
                        ContentTemplate="{StaticResource ContentTemplate}"
                        TileStateChanged="ClassOverridesTileView_TileStateChanged"
                         >
        </my:RadTileView>

Why would the source of the event be different for me than the examples?

9 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 12 Jul 2010, 07:50 AM
Hi kilhoffer,

the event source is the TileView, not the TileViewItem. You need to use the e.OriginalSource to get the TileViewItem.

Please let us know if you have more questions.

Greetings,
Valentin.Stoychev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Robin
Top achievements
Rank 1
answered on 13 Jul 2010, 10:43 AM
I just tried both e.source and e.originalsource and both return the object of type RadTileView and NOT RadTileViewItem.

Any ideas, I also need to get a handle on the RadTileViewItem

Thanks
Chris
0
Robin
Top achievements
Rank 1
answered on 13 Jul 2010, 10:50 AM
Is ok I have discovered what was wrong I was wiring up the wrong event...

TilesStateChanged

and should have wired up

TileStateChanged (with out the s)

:)
chris
0
kilhoffer
Top achievements
Rank 1
answered on 13 Jul 2010, 03:38 PM
So the samples are incorrect? The samples show the Source as being the RadTileViewItem.
0
Kiril Stanoev
Telerik team
answered on 15 Jul 2010, 04:02 PM
Hello kilhoffer,

If you define your TileView in XAML and subscribe for TileStateChanged event of RadTileView then the e.Source and e.OriginalSource will be a RadTileViewItem. For example, take this scenario:

<telerikNavigation:RadTileView TileStateChanged="RadTileView_TileStateChanged">
    <telerikNavigation:RadTileViewItem Header="Item 0" />
    <telerikNavigation:RadTileViewItem Header="Item 1" />
    <telerikNavigation:RadTileViewItem Header="Item 2" />
    <telerikNavigation:RadTileViewItem Header="Item 3" />
</telerikNavigation:RadTileView>

private void RadTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    // here e.Source is RadTileViewItem and e.OriginalSource is RadTileViewItem
}

However, since you are binding RadTileView, the e.Source will be RadTileView, while the e.OriginalSource will be RadTileViewItem.

<telerikNavigation:RadTileView x:Name="tileView1"
        TileStateChanged="RadTileView_TileStateChanged" />

public MainWindow()
{
    InitializeComponent();
    this.tileView1.ItemsSource = Enumerable.Range(0, 4);
}
 
private void RadTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    // here e.Source is RadTileView and e.OriginalSource is RadTileViewItem
}

Most of the examples on our website do not have binding and in all of them the TileViewItems are defined in XAML. That is why the e.Source is RadTileViewItem.

Greetings,
Kiril Stanoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vijay
Top achievements
Rank 1
answered on 19 Jul 2011, 10:17 AM
Hi

I put one usercontrol in tileview datatemplate but I am not able get that usercontrol at time of state change.

 <telerik:RadTileView.ContentTemplate>
                <DataTemplate>
                    <My:DocumentViewer x:Name="SPDocumentViewer" 
                                       MinHeight="100" MinWidth="100" FilePath="{Binding FilePath}" 
                                       paramFromPage="{Binding Sheetno}" paramToPage="{Binding Sheetno}"/>
                </DataTemplate>
            </telerik:RadTileView.ContentTemplate>


Thanks
Vijay 
0
Kiril Stanoev
Telerik team
answered on 21 Jul 2011, 12:23 PM
Hi Vijay,

One way to achieve what you're looking for is to use out ChildrenOfType<T> extension method. Something like this:

private void RadTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadTileViewItem item = e.OriginalSource as RadTileViewItem;
    MyUserControl myUserControl = item.ChildrenOfType<MyUserControl>().FirstOrDefault();
    if(myUserControl != null)
    {
        // MyUserControl found!
    }
}

However, I'd advice you to use this extension method with caution because it traverses the visual tree of the control (in this case RadTileViewItem) and if the visual tree is large this will impose performance issues. For further reference, please take a look at the attached project.

Regards,
Kiril Stanoev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Mike
Top achievements
Rank 1
answered on 16 Aug 2011, 09:27 PM
Hi Kiril,

I'm using WPF, TileView with Fluidcontenetcontrl. using the folllowing event handler to change the fluidContols state to change my datatemplate but item.Content as RadFluidContentControl is null! The item is picked up correctly.

what am i doing wrong?

Thanks,
Mike

 private void RadTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadTileViewItem item = e.OriginalSource as RadTileViewItem;
            if (item != null)
            {
                RadFluidContentControl fluidControl = item.Content as RadFluidContentControl;
                if (fluidControl != null)
                {
                    switch (item.TileState)
                    {
                        case TileViewItemState.Maximized:
                            fluidControl.State = FluidContentControlState.Large;
                            break;
                        case TileViewItemState.Minimized:
                            fluidControl.State = FluidContentControlState.Small;
                            break;
                        case TileViewItemState.Restored:
                            fluidControl.State = FluidContentControlState.Normal;
                            break;
                    }
                }
            }


0
Zarko
Telerik team
answered on 19 Aug 2011, 12:20 PM
Hi Mike,
The item.Content as RadFluidContentControl will work only if your TileView items are RadTileVIewItem (defined in XAML or created added in code behind) i.e. you don't use binding. When you're using business objects for items in your RadTileView you can find the RadFluidContentConrol like this:
RadFluidContentControl fluidControl = item.ChildrenOfType<RadFluidContentControl>().FirstOrDefault();
For further references could you please examine the attached project and if you have more questions feel free to ask.

All the best,
Zarko
the Telerik team

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

Tags
TileView
Asked by
kilhoffer
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Robin
Top achievements
Rank 1
kilhoffer
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Vijay
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Zarko
Telerik team
Share this question
or