RadTileViewItem not the source of TileStateChanged event

10 posts, 0 answers
  1. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 09 Jul 2010 Link to this post

    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?
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 12 Jul 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robin
    Robin avatar
    10 posts
    Member since:
    Jun 2009

    Posted 13 Jul 2010 Link to this post

    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
  5. Robin
    Robin avatar
    10 posts
    Member since:
    Jun 2009

    Posted 13 Jul 2010 Link to this post

    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
  6. kilhoffer
    kilhoffer avatar
    40 posts
    Member since:
    May 2007

    Posted 13 Jul 2010 Link to this post

    So the samples are incorrect? The samples show the Source as being the RadTileViewItem.
  7. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 15 Jul 2010 Link to this post

    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
  8. Vijay
    Vijay avatar
    22 posts
    Member since:
    Dec 2010

    Posted 19 Jul 2011 Link to this post

    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 
  9. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 21 Jul 2011 Link to this post

    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!

  10. Mike
    Mike avatar
    2 posts
    Member since:
    May 2011

    Posted 16 Aug 2011 Link to this post

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


  11. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 19 Aug 2011 Link to this post

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

Back to Top
UI for WPF is Visual Studio 2017 Ready