The default GroupStyle indents the items in a group : Style « Windows Presentation Foundation « C# / CSharp Tutorial






<Window 
    x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfApplication1="clr-namespace:WpfApplication1"
    Title="WPF" Height="300" Width="160">

    <Window.Resources>
        <WpfApplication1:Countries x:Key="countries"/>
        <WpfApplication1:GroupByContinentConverter x:Key="GroupByContinentConverter"/>
        <CollectionViewSource 
            x:Key="cvs" 
            Source="{Binding Source={StaticResource countries}}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription Converter="{StaticResource GroupByContinentConverter}" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    <Grid>
        <ItemsControl ItemsSource="{Binding Source={StaticResource cvs}}" DisplayMemberPath="Name" >
            <ItemsControl.GroupStyle>
                <x:Static Member="GroupStyle.Default"/>
            </ItemsControl.GroupStyle>
        </ItemsControl>

    </Grid>
</Window>
//File:Window.xaml.cs

using System;
using System.Globalization;
using System.Windows.Data;
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    public class GroupByContinentConverter : IValueConverter
    {
        public object Convert(object value,Type targetType,object parameter,CultureInfo culture)
        {
            Country country = (Country)value;
            // Decide which group the country belongs in
            switch (country.Continent)
            {
                case Continent.NorthAmerica:
                    return "Americas";
                default:
                    return "Others";
            }
        }

        public object ConvertBack(object value,Type targetType,object parameter,CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class Country
    {
        private string name;
        private Continent continent;

        public Country(string name, Continent continent)
        {
            this.name = name;
            this.continent = continent;
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public Continent Continent
        {
            get
            {
                return continent;
            }
            set
            {
                continent = value;
            }
        }
    }

    public enum Continent
    {
        Europe,
        NorthAmerica,
    }

    public class Countries : Collection<Country>
    {
        public Countries()
        {
            this.Add(new Country("Great Britan", Continent.Europe));
            this.Add(new Country("USA", Continent.NorthAmerica));
            this.Add(new Country("Canada", Continent.NorthAmerica));
        }
    }
}
WPF The Default Group Style Indents The Items In A Group








24.66.Style
24.66.1.Double value as the Font sizeDouble value as the Font size
24.66.2.FontFamily resource constantFontFamily resource constant
24.66.3.Styles With Same KeysStyles With Same Keys
24.66.4.Setter With Binding to SliderSetter With Binding to Slider
24.66.5.Style With Data TriggerStyle With Data Trigger
24.66.6.Styles With Target TypesStyles With Target Types
24.66.7.Style With Multiple ElementsStyle With Multiple Elements
24.66.8.Style With Multiple ButtonsStyle With Multiple Buttons
24.66.9.Style With ResourceStyle With Resource
24.66.10.Style With Property ElementStyle With Property Element
24.66.11.Style With TriggersStyle With Triggers
24.66.12.Style Slider: Background, IsSnapToTickEnabled, AutoToolTipPlacement, TickFrequencyStyle Slider: Background, IsSnapToTickEnabled, AutoToolTipPlacement, TickFrequency
24.66.13.Normal: Origin at upper leftNormal: Origin at upper left
24.66.14.Stroke Start Line CapStroke Start Line Cap
24.66.15.Property TriggerProperty Trigger
24.66.16.Using a Style resourceUsing a Style resource
24.66.17.Sharing a StyleSharing a Style
24.66.18.Ignore an Implicit Style by setting Style to NullIgnore an Implicit Style by setting Style to Null
24.66.19.Set a Style ProgrammaticallySet a Style Programmatically
24.66.20.extends StyleSelector to create your own style selectorextends StyleSelector to create your own style selector
24.66.21.The default GroupStyle indents the items in a groupThe default GroupStyle indents the items in a group