Articles in this section

How to maximize the TileViewItem from code behind in WPF?

This article explains how to programmatically maximize a tile in the Syncfusion WPF TileViewControl from code‑behind when items are populated using data binding. This scenario is useful when you want to control the state of a TileView item based on user interaction such as a button click, menu command, or application logic instead of relying only on mouse interactions within the TileViewControl.

In WPF TileViewControl, each data item is wrapped in a TileViewItem container. To change the visual state (Normal, Minimized, or Maximized) of a tile from code‑behind, you must first retrieve its corresponding TileViewItem container using the ItemContainerGenerator. Once obtained, you can set the TileViewItemState property to Maximized.

Steps to maximize a TileView item from code‑behind
Step 1: Define the TileViewControl in XAML

Create a TileViewControl and bind it to a collection using ItemsSource and use ItemContainerStyle to bind the Header and Content properties. Also, add a button to trigger the maximize action.

<Button Margin="10" Content="Click to Maximize Item1" Click="Button_Click" Width="150" />

<syncfusion:TileViewControl Height="300" ItemsSource="{Binding TileViewItems}" 
                    Name="tileViewControl">
    <syncfusion:TileViewControl.ItemContainerStyle>
        <Style TargetType="{x:Type syncfusion:TileViewItem}">
            <Setter Property="Header" Value="{Binding Header}" />
            <Setter Property="Content" Value="{Binding Content}"/>
        </Style>
    </syncfusion:TileViewControl.ItemContainerStyle>

    <syncfusion:TileViewControl.DataContext>
        <local:ViewModel/>
    </syncfusion:TileViewControl.DataContext>
</syncfusion:TileViewControl>
Step 2: Populate the TileViewControl

Use an ObservableCollection in the ViewModel and populate it with TileView items. The collection is automatically reflected in the UI due to data binding.

class ViewModel : NotificationObject
{
   private ObservableCollection<TileItem> tileViewItems;

   public ObservableCollection<TileItem> TileViewItems
   {
       get { return tileViewItems; }
       set
       {
           tileViewItems = value;
           this.RaisePropertyChanged(nameof(TileViewItems));
       }
   }

   public ViewModel()
   {
       tileViewItems = new ObservableCollection<TileItem>();
       PopulateCollection();
   }

   public void PopulateCollection()
   {
       //Adding the tileview items into the collection
       TileViewItems.Add(new TileItem() { Header = "Item 1", Content = "Content 1" });
       TileViewItems.Add(new TileItem() { Header = "Item 2", Content = "Content 2" });
       TileViewItems.Add(new TileItem() { Header = "Item 3", Content = "Content 3" });
       TileViewItems.Add(new TileItem() { Header = "Item 4", Content = "Content 4" });
   }
} 
Step 3: Maximize a TileView item from code‑behind

Handle the button click event and retrieve the container for the required item (for example, the first item). Set its TileViewItemState to Maximized.

private void Button_Click(object sender, RoutedEventArgs e)
{
   // Assuming you want to maximize the first item
   var item = tileViewControl.Items[0];

   // Retrieve the corresponding TileViewItem container
   var container = tileViewControl.ItemContainerGenerator.ContainerFromItem(item) as TileViewItem;

   if (container != null)
   {
      container.TileViewItemState = Syncfusion.Windows.Shared.TileViewItemState.Maximized;
   }

   // Alternative approach if the TileViewItem is explicitly named in XAML
   // this.tile1.TileViewItemState = Syncfusion.Windows.Shared.TileViewItemState.Maximized;
} 
Output:

When the button is clicked, the first TileView item is programmatically maximized, occupying the available TileViewControl space while the remaining tiles are automatically minimized.

DemoVideo.gif

Related documentation and samples:

User Guide – TileViewControl Data Binding Support
Learn more about binding TileViewControl with MVVM, collections, and templates: https://help.syncfusion.com/wpf/tile-view/data-binding-support

Sample
Refer to the attached sample for a complete working example that demonstrates how to maximize a TileView item from code‑behind when the TileViewControl is data‑bound.

Conclusion:

I hope you enjoyed learning about how to maximize the TileViewItem from code behind in WPF TileViewControl.

You can refer to our WPF TileViewControl feature tour page to know about its other groundbreaking feature representations documentation and how to quickly get started for configuration specifications to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied