Click here to Skip to main content
16,005,181 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Databinding? Pin
Pete O'Hanlon2-Jun-09 0:40
mvePete O'Hanlon2-Jun-09 0:40 
GeneralRe: Databinding? Pin
#realJSOP2-Jun-09 2:25
professional#realJSOP2-Jun-09 2:25 
GeneralRe: Databinding? Pin
Pete O'Hanlon2-Jun-09 2:32
mvePete O'Hanlon2-Jun-09 2:32 
GeneralRe: Databinding? Pin
#realJSOP2-Jun-09 3:11
professional#realJSOP2-Jun-09 3:11 
GeneralRe: Databinding? Pin
Pete O'Hanlon2-Jun-09 3:16
mvePete O'Hanlon2-Jun-09 3:16 
GeneralRe: Databinding? Pin
#realJSOP2-Jun-09 3:28
professional#realJSOP2-Jun-09 3:28 
QuestionList Control in WPF Pin
krishnan.s1-Jun-09 21:45
krishnan.s1-Jun-09 21:45 
AnswerRe: List Control in WPF Pin
Pete O'Hanlon1-Jun-09 23:10
mvePete O'Hanlon1-Jun-09 23:10 
Why do you need to create a custom list control? The whole point behind the controls in WPF is that they are "lookless". In other words, their behaviour is separated from the visuals, so you can restyle existing controls with relative ease.

Here's a (pretty completely) restyled version of a ListBox (thanks to KaXAML):
<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
   <Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ScrollViewer}">
   <Grid Background="{TemplateBinding Background}">
     <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="Auto"/>
     </Grid.ColumnDefinitions>
     <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
     </Grid.RowDefinitions>
     <DockPanel Margin="{TemplateBinding Padding}">
    <ScrollViewer
      DockPanel.Dock="Top"
      Focusable="false"
      HorizontalScrollBarVisibility="Hidden"
      VerticalScrollBarVisibility="Hidden">
      <GridViewHeaderRowPresenter
     Margin="2,0,2,0"
     AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
     ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
     ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
     ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
     ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
     ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"
     Columns="{Binding Path=TemplatedParent.View.Columns,RelativeSource={RelativeSource TemplatedParent}}"
     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    </ScrollViewer>
    <ScrollContentPresenter Name="PART_ScrollContentPresenter" KeyboardNavigation.DirectionalNavigation="Local"/>
     </DockPanel>
     <ScrollBar
    Name="PART_HorizontalScrollBar"
    Grid.Row="1"
    Maximum="{TemplateBinding ScrollableWidth}"
    Orientation="Horizontal"
    Value="{TemplateBinding HorizontalOffset}"
    ViewportSize="{TemplateBinding ViewportWidth}"
    Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
     <ScrollBar
    Name="PART_VerticalScrollBar"
    Grid.Column="1"
    Maximum="{TemplateBinding ScrollableHeight}"
    Value="{TemplateBinding VerticalOffset}"
    ViewportSize="{TemplateBinding ViewportHeight}"
    Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
   </Grid>
    </ControlTemplate>
  </Setter.Value>
   </Setter>
 </Style>
 <Style x:Key="GridViewColumnHeaderGripper" TargetType="{x:Type Thumb}">
   <Setter Property="Width" Value="18"/>
   <Setter Property="Background" Value="#404040"/>
   <Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type Thumb}">
   <Border Background="Transparent" Padding="{TemplateBinding Padding}">
     <Rectangle Width="1" HorizontalAlignment="Center" Fill="{TemplateBinding Background}"/>
   </Border>
    </ControlTemplate>
  </Setter.Value>
   </Setter>
 </Style>
 <Style x:Key="{x:Type GridViewColumnHeader}" TargetType="{x:Type GridViewColumnHeader}">
   <Setter Property="HorizontalContentAlignment" Value="Center"/>
   <Setter Property="VerticalContentAlignment" Value="Center"/>
   <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
   <Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
   <Grid>
     <Border
    Name="HeaderBorder"
    Background="#E0E0E0"
    BorderBrush="#404040"
    BorderThickness="0,1,0,1"
    Padding="2,0,2,0">
    <ContentPresenter
      Name="HeaderContent"
      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
      Margin="0,0,0,1"
      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
      RecognizesAccessKey="True"
      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
     </Border>
     <Thumb
    x:Name="PART_HeaderGripper"
    HorizontalAlignment="Right"
    Margin="0,0,-9,0"
    Style="{StaticResource GridViewColumnHeaderGripper}"/>
   </Grid>
   <ControlTemplate.Triggers>
     <Trigger Property="IsMouseOver" Value="true">
    <Setter TargetName="HeaderBorder" Property="Background" Value="#C0C0C0"/>
     </Trigger>
     <Trigger Property="IsPressed" Value="true">
    <Setter TargetName="HeaderBorder" Property="Background" Value="#E0E0E0"/>
    <Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
     </Trigger>
     <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
     </Trigger>
   </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
   </Setter>
   <Style.Triggers>
  <Trigger Property="Role" Value="Floating">
    <Setter Property="Opacity" Value="0.7"/>
    <Setter Property="Template">
   <Setter.Value>
     <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
    <Canvas Name="PART_FloatingHeaderCanvas">
      <Rectangle Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Fill="#60000000"/>
    </Canvas>
     </ControlTemplate>
   </Setter.Value>
    </Setter>
  </Trigger>
  <Trigger Property="Role" Value="Padding">
    <Setter Property="Template">
   <Setter.Value>
     <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
    <Border
      Name="HeaderBorder"
      Background="#E0E0E0"
      BorderBrush="#404040"
      BorderThickness="0,1,0,1"/>
     </ControlTemplate>
   </Setter.Value>
    </Setter>
  </Trigger>
   </Style.Triggers>
 </Style>
 <Style x:Key="{x:Type ListView}" TargetType="{x:Type ListView}">
   <Setter Property="SnapsToDevicePixels" Value="true"/>
   <Setter Property="OverridesDefaultStyle" Value="true"/>
   <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
   <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
   <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
   <Setter Property="VerticalContentAlignment" Value="Center"/>
   <Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ListView}">
   <Border
     Name="Border"
     Background="#FFFFFF"
     BorderBrush="#888888"
     BorderThickness="1">
     <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
    <ItemsPresenter/>
     </ScrollViewer>
   </Border>
   <ControlTemplate.Triggers>
     <Trigger Property="IsGrouping" Value="true">
    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
     </Trigger>
     <Trigger Property="IsEnabled" Value="false">
    <Setter TargetName="Border" Property="Background" Value="#AAAAAA"/>
     </Trigger>
   </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
   </Setter>
 </Style>
 <Style x:Key="{x:Type ListViewItem}" TargetType="{x:Type ListViewItem}">
   <Setter Property="SnapsToDevicePixels" Value="true"/>
   <Setter Property="OverridesDefaultStyle" Value="true"/>
   <Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ListBoxItem}">
   <Border
     Name="Border"
     Background="Transparent"
     Padding="2"
     SnapsToDevicePixels="true">
     <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
   </Border>
   <ControlTemplate.Triggers>
     <Trigger Property="IsSelected" Value="true">
    <Setter TargetName="Border" Property="Background" Value="#DDDDDD"/>
     </Trigger>
     <Trigger Property="IsEnabled" Value="false">
    <Setter Property="Foreground" Value="#888888"/>
     </Trigger>
   </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
   </Setter>
 </Style>


"WPF has many lovers. It's a veritable porn star!" - Josh Smith

As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.


My blog | My articles | MoXAML PowerToys | Onyx



QuestionWord wrap in RichTextBox Pin
hain1-Jun-09 10:25
hain1-Jun-09 10:25 
Questionhow to close a window.. Pin
Hema Bairavan1-Jun-09 0:18
Hema Bairavan1-Jun-09 0:18 
AnswerRe: how to close a window.. Pin
ABitSmart1-Jun-09 6:00
ABitSmart1-Jun-09 6:00 
QuestionVisualChildrenCount.. Pin
Hema Bairavan1-Jun-09 0:10
Hema Bairavan1-Jun-09 0:10 
AnswerRe: VisualChildrenCount.. Pin
Pete O'Hanlon1-Jun-09 1:28
mvePete O'Hanlon1-Jun-09 1:28 
GeneralRe: VisualChildrenCount.. Pin
Hema Bairavan1-Jun-09 1:33
Hema Bairavan1-Jun-09 1:33 
GeneralRe: VisualChildrenCount.. Pin
Pete O'Hanlon1-Jun-09 1:46
mvePete O'Hanlon1-Jun-09 1:46 
Questiontaking the control Pin
Hema Bairavan31-May-09 22:29
Hema Bairavan31-May-09 22:29 
AnswerRe: taking the control Pin
ABitSmart31-May-09 22:46
ABitSmart31-May-09 22:46 
AnswerRe: taking the control Pin
Pete O'Hanlon31-May-09 22:47
mvePete O'Hanlon31-May-09 22:47 
GeneralRe: taking the control Pin
Hema Bairavan31-May-09 22:58
Hema Bairavan31-May-09 22:58 
GeneralRe: taking the control Pin
Pete O'Hanlon31-May-09 23:04
mvePete O'Hanlon31-May-09 23:04 
GeneralRe: taking the control Pin
Hema Bairavan31-May-09 23:14
Hema Bairavan31-May-09 23:14 
GeneralRe: taking the control Pin
Hema Bairavan31-May-09 23:27
Hema Bairavan31-May-09 23:27 
QuestionPlz help in couple of think in ListView Pin
wasimsharp31-May-09 19:13
wasimsharp31-May-09 19:13 
AnswerRe: Plz help in couple of think in ListView Pin
ABitSmart31-May-09 20:38
ABitSmart31-May-09 20:38 
Questionhow to animate the button in sequencial mode ? Pin
Feras Mazen Taleb31-May-09 1:53
Feras Mazen Taleb31-May-09 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.