)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to access the element inside the maximized item template in SfTileView?

Platform: UWP |
Control: SfTileView |
Published Date: April 6, 2018 |
Last Revised Date: January 8, 2020

We can retrieve the element in the MaximizedItemTemplate of SfTileViewItem using GetChild() method of VisualTreeHelper class. For instance, we have retrieved the border(“MaximizedItemBorder”) element from the MaximizedTileItem template and change the background color of the element. The following code illustrate the same,

Template for MaximizedTileItem:

     <DataTemplate x:Key="MaximizedTileItemTemplate">
            <Border x:Name="MaximizedItemborder">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid  Grid.ColumnSpan="2" >
                        <TextBlock Text="{Binding}" FontSize="25" 
                                        Margin="20" Foreground="Black"/>
                    </Grid>
 
                    <RichTextBlock Grid.ColumnSpan="2" Grid.Row="2" VerticalAlignment="Top"  TextWrapping="Wrap"
                                           Margin="20" FontSize="14" FontWeight="Light" Foreground="Black">
                        <Paragraph LineHeight="30">
                            <Run>
                                 SfTileView acts as a container that holds a set of tile view items that can contain any content. Items can be maximized, minimized, dragged to reorder and arranged in matrix position to achieve best layout.
                            </Run>
                        </Paragraph>
                    </RichTextBlock>
                    <StackPanel VerticalAlignment="Center" Margin="20 0" Orientation="Horizontal" Grid.Row="3" Grid.ColumnSpan="2">
                        <Grid>
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="FontSize" Value="14"/>
                                    <Setter Property="Foreground" Value="White"/>
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Image Source="ms-appx:///Image/Emp_02.png" Margin="5 0" />
                            <TextBlock Text="{Binding Phone}" Grid.Column="1" Margin="5 0" VerticalAlignment="Center"/>
                        </Grid>
                    </StackPanel>
 
                </Grid>
            </Border>
        </DataTemplate>

 

MainPage.xaml:

<syncfusion:SfTileView Grid.Row="1" x:Name="sftileview" MaximizedItemTemplate="{StaticResource MaximizedTileItemTemplate}">
            <syncfusion:SfTileViewItem Content="TileItem1" Background="AliceBlue"/>
            <syncfusion:SfTileViewItem Content="TileItem2" Background="Orange"/>
            <syncfusion:SfTileViewItem Content="TileItem3" Background="Blue"/>
            <syncfusion:SfTileViewItem Content="TileItem4" Background="Coral"/>
            <syncfusion:SfTileViewItem Content="TileItem5" Background="DarkCyan"/>
        </syncfusion:SfTileView>

 

Method to get the required element:

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

 

Method to change the background of the Border element:

private void ChangeBackColor()
        {
            foreach (Border border in FindVisualChildren<Border>(this))
            {
                if (border.Name == "MaximizedItemborder")
                {
                    Random r = new Random();
                    Color randomColor = Color.FromArgb((byte)r.Next(0, 256), (byte)(r.Next(0, 256)), (byte)0, (byte)(r.Next(0, 256)));
                    border.Background = new SolidColorBrush(randomColor);
                }
            }
        }

 

Sample : http://www.syncfusion.com/downloads/support/directtrac/general/ze/TileViewSample_MaximizedItemTemplate-1710628963.zip

 

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon