changeset 47:376c72183392

selection
author Steven Hollidge <stevenhollidge@hotmail.com>
date Fri, 06 Apr 2012 23:09:53 +0100
parents 8e6458270599
children d617b54e1f47
files WrappingListbox/WrappingListbox/MainWindow.xaml WrappingListbox/WrappingListbox/WrappingListbox.csproj
diffstat 2 files changed, 105 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/WrappingListbox/WrappingListbox/MainWindow.xaml	Fri Apr 06 17:13:35 2012 +0100
+++ b/WrappingListbox/WrappingListbox/MainWindow.xaml	Fri Apr 06 23:09:53 2012 +0100
@@ -1,38 +1,113 @@
 <Window x:Class="WrappingListbox.MainWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:s="clr-namespace:System;assembly=mscorlib"
         Title="Wrapping Listbox"
         Width="525"
         Height="350"
-        Icon="ICON.ico"
-        mc:Ignorable="d">
-    <Grid>
-        <ListBox x:Name="listbox1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
+        Icon="ICON.ico">
 
-                    </Setter.Value>
-                </Setter>
-            </Style>
-            <!--
-                <VisualStateManager.VisualStateGroups>
-                <VisualStateGroup x:Name="CommonStates">
-                <VisualState x:Name="Normal" />
-                <VisualState x:Name="MouseOver">
-                <Storyboard>
-                <ColorAnimation Duration="0:0:0.5"
-                Storyboard.TargetName="Rect"
-                Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
-                To="Gainsboro" />
-                </Storyboard>
-                </VisualState>
-                </VisualStateGroup>
-                <VisualStateGroup x:Name="SelectionStates">
-                <VisualState x:Name="Unselected" />
-                <VisualState x:Name="Selected" />
-                </VisualStateGroup>
-                </VisualStateManager.VisualStateGroups>
-            -->
+    <Window.Resources>
+       <Style x:Key="CustomListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
+            <Style.Resources>
+                <ResourceDictionary />
+            </Style.Resources>
+            <Setter Property="Panel.Background">
+                <Setter.Value>
+                    <SolidColorBrush>
+                        #00FFFFFF</SolidColorBrush>
+                </Setter.Value>
+            </Setter>
+            <Setter Property="Control.HorizontalContentAlignment">
+                <Setter.Value>
+                    <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
+                </Setter.Value>
+            </Setter>
+            <Setter Property="Control.VerticalContentAlignment">
+                <Setter.Value>
+                    <Binding Path="VerticalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
+                </Setter.Value>
+            </Setter>
+            <Setter Property="Control.Padding">
+                <Setter.Value>
+                    <Thickness>
+                        2,0,0,0</Thickness>
+                </Setter.Value>
+            </Setter>
+            <Setter Property="Control.Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
+                        <Border Name="Bd"
+                                Background="{TemplateBinding Panel.Background}"
+                                BorderBrush="{TemplateBinding Border.BorderBrush}"
+                                BorderThickness="{TemplateBinding Border.BorderThickness}"
+                                Padding="{TemplateBinding Control.Padding}"
+                                SnapsToDevicePixels="True">
+                            <ContentPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
+                                              VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
+                                              Content="{TemplateBinding ContentControl.Content}"
+                                              ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
+                                              ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
+                                              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
+                        </Border>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="Selector.IsSelected">
+                                <Setter TargetName="Bd" Property="CornerRadius" Value="15" />
+                                <Setter TargetName="Bd" Property="Panel.Background" Value="Gainsboro" />
+                                <Setter Property="TextElement.Foreground">
+                                    <Setter.Value>
+                                        <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
+                                    </Setter.Value>
+                                </Setter>
+                                <Trigger.Value>
+                                    <s:Boolean>True</s:Boolean>
+                                </Trigger.Value>
+                            </Trigger>
+                            <MultiTrigger>
+                                <MultiTrigger.Conditions>
+                                    <Condition Property="Selector.IsSelected">
+                                        <Condition.Value>
+                                            <s:Boolean>True</s:Boolean>
+                                        </Condition.Value>
+                                    </Condition>
+                                    <Condition Property="Selector.IsSelectionActive">
+                                        <Condition.Value>
+                                            <s:Boolean>False</s:Boolean>
+                                        </Condition.Value>
+                                    </Condition>
+                                </MultiTrigger.Conditions>
+                                <Setter TargetName="Bd" Property="Panel.Background">
+                                    <Setter.Value>
+                                        <DynamicResource ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
+                                    </Setter.Value>
+                                </Setter>
+                                <Setter Property="TextElement.Foreground">
+                                    <Setter.Value>
+                                        <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
+                                    </Setter.Value>
+                                </Setter>
+                            </MultiTrigger>
+                            <Trigger Property="UIElement.IsEnabled">
+                                <Setter Property="TextElement.Foreground">
+                                    <Setter.Value>
+                                        <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
+                                    </Setter.Value>
+                                </Setter>
+                                <Trigger.Value>
+                                    <s:Boolean>False</s:Boolean>
+                                </Trigger.Value>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </Window.Resources>
+
+    <Grid>
+        <ListBox x:Name="listbox1"
+                 ItemContainerStyle="{StaticResource CustomListBoxItemStyle}"
+                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
             <ListBox.ItemsPanel>
                 <ItemsPanelTemplate>
                     <WrapPanel ItemHeight="100"
--- a/WrappingListbox/WrappingListbox/WrappingListbox.csproj	Fri Apr 06 17:13:35 2012 +0100
+++ b/WrappingListbox/WrappingListbox/WrappingListbox.csproj	Fri Apr 06 23:09:53 2012 +0100
@@ -15,6 +15,8 @@
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
+    <Utf8Output>true</Utf8Output>
+    <ExpressionBlendVersion>4.0.20525.0</ExpressionBlendVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <PlatformTarget>x86</PlatformTarget>