Click here to Skip to main content
15,892,537 members
Articles / Desktop Programming / WPF

WPF.JoshSmith

Rate me:
Please Sign up or sign in to vote.
4.99/5 (51 votes)
13 Jul 2008CPOL5 min read 390.9K   4.8K   263  
A free library of controls and utility classes for use in WPF applications.
<Window x:Class="Test.ListViewDragDropManager.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:jas="clr-namespace:WPF.JoshSmith.ServiceProviders.UI;assembly=WPF.JoshSmith" 
    Title="ListViewDragDropManager Demo" Height="600" Width="700"
    FontSize="12"
    WindowStartupLocation="CenterScreen"
    >
  <Window.Resources>
    <Style x:Key="ItemContStyle" TargetType="ListViewItem">
      <Style.Resources>
        <LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">
          <GradientStop Color="#22000000" Offset="0" />
          <GradientStop Color="#44000000" Offset="0.4" />
          <GradientStop Color="#55000000" Offset="0.6" />
          <GradientStop Color="#33000000" Offset="0.9" />
          <GradientStop Color="#22000000" Offset="1" />
        </LinearGradientBrush>
      </Style.Resources>
      <Setter Property="Padding" Value="0,4" />
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
      <!-- The default control template for ListViewItem has a Border 
           which contains the item's content. -->
      <Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />
      <Setter Property="Border.BorderBrush" Value="LightGray" />
      <!-- These triggers react to changes in the attached properties set
           during a managed drag-drop operation. -->
      <Style.Triggers>
        <Trigger Property="jas:ListViewItemDragState.IsBeingDragged" Value="True">
          <Setter Property="FontWeight" Value="DemiBold" />
        </Trigger>
        <Trigger Property="jas:ListViewItemDragState.IsUnderDragCursor" Value="True">
          <Setter Property="Background" Value="{StaticResource MouseOverBrush}" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </Window.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <GroupBox Header="Main ListView Settings" Grid.Row="0" Margin="4" Padding="2">
      <StackPanel>
        <StackPanel.Resources>
          <Style TargetType="CheckBox">
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="IsChecked" Value="True" />
          </Style>
        </StackPanel.Resources>
        <CheckBox 
          Name="chkManageDragging" 
          Margin="4"
          >
          Manage Dragging of ListViewItems
        </CheckBox>
        <StackPanel Margin="4" IsEnabled="{Binding ElementName=chkManageDragging, Path=IsChecked}">
          <CheckBox 
            Name="chkDragAdorner" 
            Margin="0,4" 
            >
            Show Drag Adorner
          </CheckBox>
          <StackPanel Orientation="Horizontal" Margin="0,4" IsEnabled="{Binding ElementName=chkDragAdorner, Path=IsChecked}">
            <Label>Drag Adorner Opacity:</Label>
            <Slider Name="sldDragOpacity" Value="0.7" Minimum="0" Maximum="1" Width="90" Margin="4" />
            <Label Content="{Binding ElementName=sldDragOpacity, Path=Value}" />
          </StackPanel>
        </StackPanel>
        <Line Stroke="DarkGray" Stretch="Fill" StrokeThickness="0.5" X1="0" X2="1" />
        <CheckBox 
          Name="chkApplyContStyle" 
          Margin="4,8,4,4"
          ToolTip="If checked, the ListView's ItemContainerStyle is set to a Style which reacts to the drag operation."
          >
          Apply Item Container Style
        </CheckBox>
        <CheckBox 
          Name="chkSwapDroppedItem" 
          IsChecked="False" 
          Margin="4" 
          ToolTip="If checked, the dropped item and the item at the target index will exchange locations."
          >
          Use Custom Drop Logic
        </CheckBox>
        <CheckBox 
          Name="chkShowOtherListView" 
          IsChecked="False"
          Margin="4" 
          ToolTip="If checked, another ListView is visible.  The items from one ListView can be dropped into the other ListView."
          >
          Show Other ListView
        </CheckBox>
      </StackPanel>
    </GroupBox>

    <ListView Name="listView"       
      Grid.Row="1"   
      ItemContainerStyle="{StaticResource ItemContStyle}"
      Margin="4" 
      Padding="2"
      SelectionMode="Single"
      >
      <ListView.View>
        <GridView>
          <GridViewColumn Header="Finished">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <CheckBox IsChecked="{Binding Finished}" HorizontalAlignment="Center" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn Header="Duration" DisplayMemberBinding="{Binding Duration}" Width="80" />
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="175" />
          <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="340" />
        </GridView>
      </ListView.View>
    </ListView>

    <ListView Name="listView2"
      Grid.Row="2"  
      Height="185" 
      ItemContainerStyle="{StaticResource ItemContStyle}"
      Margin="4" 
      Padding="2"
      SelectionMode="Single"
      Visibility="Collapsed"
      >
      <ListView.View>
        <GridView>
          <GridViewColumn Header="Finished">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <CheckBox IsChecked="{Binding Finished}" HorizontalAlignment="Center" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn Header="Duration" DisplayMemberBinding="{Binding Duration}" Width="80" />
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="175" />
          <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="340" />
        </GridView>
      </ListView.View>
    </ListView>
  </Grid>
</Window>

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)


Written By
Software Developer (Senior)
United States United States
Josh creates software, for iOS and Windows.

He works at Black Pixel as a Senior Developer.

Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.

Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.

Check out his Advanced MVVM[^] book.

Visit his WPF blog[^] or stop by his iOS blog[^].

See his website Josh Smith Digital[^].

Comments and Discussions