Click here to Skip to main content
12,358,393 members (67,714 online)
Click here to Skip to main content

Stats

49.2K views
816 downloads
21 bookmarked
Posted

WPF Introduction: Databinding + Styles + IValueConverter

, 5 Aug 2009 CPOL
A small introduction about Listview Databinding and Styles with introduction to IValueConverter interface
ListViewDataBindingSample
ListViewDataBindingSample
bin
Debug
ListViewDataBindingSample.exe
ListViewDataBindingSample.vshost.exe
Properties
ListViewDataBindingSample.suo
ListViewDataBindingSample.vshost.exe.manifest
<ResourceDictionary
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 xmlns:appStyles="clr-namespace:ListViewDataBindingSample">

    <!-- ListViewItem Alternate colour template-->
    <appStyles:BackgroundConverter x:Key="AlternateBackgroundConverter"/>


    <Style x:Key="ListViewAlternateItemStyle" TargetType="{x:Type ListViewItem}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Background">
            <Setter.Value>
                <Binding RelativeSource="{RelativeSource Self}" 
                 Converter="{StaticResource AlternateBackgroundConverter}"/>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border Name="Border" Margin="-3,0,1,0" Padding="0,3,0,3"
                  SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
                        <StackPanel Orientation="Horizontal">
                            <GridViewRowPresenter VerticalAlignment="Center"/>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="Border" Property="Background">
                                <Setter.Value>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FFD4DFFE" Offset="0"/>
                                        <GradientStop Color="#FFE0E4EF" Offset="1"/>
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="Border" Property="CornerRadius" Value="2"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="#888"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sathishkumar_P
Software Developer (Senior)
India India
Working in a software development company specializing financial products as Senior Developer. Interested in WPF, WCF, C# and C.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 6 Aug 2009
Article Copyright 2009 by Sathishkumar_P
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid