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

Commanding & Controls

6 Answers 67 Views
TileView
This is a migrated thread and some comments may be shown as answers.
UGH!!
Top achievements
Rank 1
UGH!! asked on 26 May 2011, 09:31 PM
I've been trying to use the TileView for a requirement I have, but I'm having trouble with both Commanding and accessing controls. 

Can you demonstrate how to access the RadGridView inside the RadTileView??

Also, when I try to use Command with a button inside the TileView, it will never fire. If I move the button outside the TileView, it works perfectly.  Is there an issue with Commanding within RadTileView??

Thanks!!

6 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 01 Jun 2011, 09:32 AM
Hello UGH!!,

I attached a sample project where the RadTileView control is databound to a collection of business objects. The ContentTemplate of the control defines a RadGridView control. You can access this RadGridView control using the Telerik extension methods for walking through the visual tree, for example when you get the RadTileViewItem you can use it to find for it a child of type RadGridView:
private void RadTileView_PreviewTileStateChanged(object sender, PreviewTileStateChangedEventArgs e)
{
    RadTileViewItem tile = e.OriginalSource as RadTileViewItem;
    if (tile.TileState == TileViewItemState.Maximized)
    {
        RadGridView grid = tile.FindChildByType<RadGridView>();
        grid.BorderBrush = new SolidColorBrush(Colors.Green);
        grid.BorderThickness = new Thickness(2);
    }
}

Also, I was unable to reproduce the issue with the button's commands so can you please let me know if the approach illustrated in the sample project works for you?

Greetings,
Tina Stancheva
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
UGH!!
Top achievements
Rank 1
answered on 24 Jun 2011, 09:17 PM
Well ... I tried that and always get "object reference" errors.  Here's what I did and it's working ...

 

 

private void _linTileView_TileStateChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadTileViewItem _tileItem = e.Source as RadTileViewItem;
            if (_tileItem != null)
            {
                if (_tileItem.TileState == TileViewItemState.Maximized)
                {
                    _linID = ((LIN)_tileItem.Header).ID;
                    ViewModel.LoadData(_linID);

                    foreach (RadGridView _radGrid in VisualTreeEnumeration.FindVisualChildren<RadGridView>(_tileItem))
                    {
                        RadContextMenu.SetContextMenu(_radGrid, _conditionContextMenu);
                    }

                    foreach (RadButton _radButtons in VisualTreeEnumeration.FindVisualChildren<RadButton>(_tileItem))
                    {
                        if (_radButtons.Name == "_btnNew") _radButtons.Command = ViewModel.AddCommand;
                        if (_radButtons.Name == "_btnEdit") _radButtons.Command = ViewModel.EditCommand;
                        if (_radButtons.Name == "_btnDelete") _radButtons.Command = ViewModel.DeleteCommand;
                    }
                }               
            }
        }


Using a static class:

 

public static class VisualTreeEnumeration
    {
        public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
        {
            if (depObj != null)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                    if (child != null && child is T)
                    {
                        yield return (T)child;
                    }

                    foreach (T childOfChild in FindVisualChildren<T>(child))
                    {
                        yield return childOfChild;
                    }
                }
            }
        }
    }

0
UGH!!
Top achievements
Rank 1
answered on 24 Jun 2011, 09:22 PM
Now .... This works except on the initial onload of the radgridview.  I have the maximizemode=One. I can get the grid to bind to the viewmodel, but cannot seem to get the Commanding to work.  As soon as I change my selection, everything binds properly.  It only is on the initial load.

Any thoughts??
0
Zarko
Telerik team
answered on 29 Jun 2011, 04:41 PM
Hello UGH!!,
I guess the problem is that the TileStateChanged event is not risen on initial loading. You can try to handle the StatusChanged event of the ItemContainerGenerator of the RadTileView and in it you can set the ContextMenu and the Command to all RadTileViewItems like this:
public MainPage()
{
    InitializeComponent();
 
    this._linTileView.ItemContainerGenerator.StatusChanged += this.ItemContainerGenerator_StatusChanged;
}
 
void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
    Telerik.Windows.Controls.ItemContainerGenerator generator = sender as Telerik.Windows.Controls.ItemContainerGenerator;
 
    if(generator != null && generator.Status == Telerik.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
    {
        foreach (var item in this._linTileView.Items)
        {
            RadTileViewItem _tileItem = generator.ContainerFromItem(item) as RadTileViewItem;
 
            if (_tileItem != null)
            {
                if (_tileItem.TileState == TileViewItemState.Maximized)
                {
                    _linID = ((LIN)_tileItem.Header).ID;
                    ViewModel.LoadData(_linID);
 
                    foreach (RadGridView _radGrid in VisualTreeEnumeration.FindVisualChildren<RadGridView>(_tileItem))
                    {
                        RadContextMenu.SetContextMenu(_radGrid, _conditionContextMenu);
                    }
 
                    foreach (RadButton _radButtons in VisualTreeEnumeration.FindVisualChildren<RadButton>(_tileItem))
                    {
                        if (_radButtons.Name == "_btnNew") _radButtons.Command = ViewModel.AddCommand;
                        if (_radButtons.Name == "_btnEdit") _radButtons.Command = ViewModel.EditCommand;
                        if (_radButtons.Name == "_btnDelete") _radButtons.Command = ViewModel.DeleteCommand;
                    }
                }
            }
        }      
    }
}
 
. . .
If you need further assistance please feel free to ask.

Greetings,
Zarko
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
UGH!!
Top achievements
Rank 1
answered on 30 Jun 2011, 04:55 PM
Unfortunately this isn't working either ... :(  This is always false.  Looks like generator is never null, and it does look like both generator.status && sender are "generatingcontainers".

 

if(generator != null && generator.Status == Telerik.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)

And TileState is "restored" and never in Maximized state, so none of the commands fire.
0
Zarko
Telerik team
answered on 05 Jul 2011, 12:13 PM
Hello Ugh!!,
Could you please examine the attached project and see if this is what you want? And also I'd like to ask you why don't you put everything you want in the DataTemplate with something like this:
<telerik:RadTileView.ContentTemplate>
    <DataTemplate>
        <Grid>
            <telerik:RadButton VerticalAlignment="Top"
                                           Command="{Binding MyCommand}"
                                           Content="Test" />
            <telerik:RadGridView HorizontalAlignment="Stretch"
                                             VerticalAlignment="Center"
                                             AutoGenerateColumns="True"
                                             ItemsSource="{Binding Products}">
                <telerik:RadContextMenu.ContextMenu>
                    <telerik:RadContextMenu>
                        <telerik:RadMenuItem Header="Add" />
                        <telerik:RadMenuItem Header="Delete" />
                        <telerik:RadMenuItem Header="Do something else" />
                    </telerik:RadContextMenu>
                </telerik:RadContextMenu.ContextMenu>
            </telerik:RadGridView>
        </Grid>
    </DataTemplate>
</telerik:RadTileView.ContentTemplate>
and don't use any code behind?

All the best,
Zarko
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
Tags
TileView
Asked by
UGH!!
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
UGH!!
Top achievements
Rank 1
Zarko
Telerik team
Share this question
or