Skip to content

DevExpress-Examples/wpf-tilebar-generate-items-from-view-model-collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF TileBar – Bind Items to a ViewModel Collection (MVVM)

The TileBar control allows you to create a Windows 10-inspired navigation UI.

Bind Items to a ViewModel Collection

Use the TileBar control with MVVM when you need to:

  • Define a dynamic navigation UI based on data rather than hard-coded items.
  • Bind a TileBar to a flat or hierarchical data structure.
  • Apply styles, group headers, commands, and flyout content from your data model.

Implementation Details

Data Structure

The ViewModel exposes an ObservableCollection<Item> as the Items property. Each Item defines the following:

  • A Name property that defines the tile's label.
  • An optional Group string to group tiles visually.
  • A collection of Children (if present) to populate the flyout.
  • A Command that runs when the item is clicked.
public class Item : BindableBase {
    public string Name { get; set; }
    public string Group { get; set; }
    public ObservableCollection<Item> Children { get; set; }
    public bool IsHasChildren => Children != null && Children.Count > 0;
    public DelegateCommand Command { get; }
}

Item Styling and Grouping

The following code example uses the ItemContainerStyle property to configure tile appearance and behavior:

<Style TargetType="{x:Type dxnav:TileBarItem}" x:Key="TileBarItemStyleBase">
    <Setter Property="Content" Value="{Binding Name}" />
    <Setter Property="Command" Value="{Binding Command}" />
</Style>

<Style TargetType="{x:Type dxnav:TileBarItem}" BasedOn="{StaticResource TileBarItemStyleBase}" x:Key="TileBarItemStyleExtended">
    <Setter Property="dxnav:TileBar.GroupHeader" Value="{Binding Group}" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding IsHasChildren}" Value="true">
            <Setter Property="FlyoutContent" Value="{Binding Children}" />
            <Setter Property="FlyoutContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <dxnav:TileBar
                            ItemsSource="{Binding}"
                            ItemContainerStyle="{StaticResource TileBarItemStyleBase}"
                            ItemColorMode="Inverted" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>

TileBar Configuration

The TileBar control is bound to the Items collection and uses the extended style:

<dxnav:TileBar
    ItemsSource="{Binding Items}"
    ItemContainerStyle="{StaticResource TileBarItemStyleExtended}" />

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Binds the WPF TileBar to a ViewModel to generate a tile-based navigation UI using the MVVM pattern.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5