<Window x:Class="WpfApplication13.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxgext="clr-namespace:DevExpress.Xpf.Grid;assembly=DevExpress.Xpf.Grid.v12.1.Extensions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
Title="MainWindow"
Width="525"
Height="350">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="rowInfoTemplate">
<dxgext:NameTextControl NameValue="Row" TextValue="{Binding Text}" />
</DataTemplate>
<DataTemplate x:Key="dragInfoTemplate">
<Border Padding="12 8 24 10">
<StackPanel>
<TextBlock Name="rowCountTextBlock" FontWeight="Bold" Foreground="#FF949494">
<TextBlock.Text>
<Binding Path="DraggingRows.Count" StringFormat="Dragging {0} rows" />
</TextBlock.Text>
<TextBlock.Visibility>
<Binding Path="DraggingRows.Count">
<Binding.Converter>
<dxgext:CountToVisibilityConverter />
</Binding.Converter>
</Binding>
</TextBlock.Visibility>
</TextBlock>
<TextBlock Name="oneRowTextBlock" FontWeight="Bold" Foreground="#FF949494" Text="Dragging 1 row:">
<TextBlock.Visibility>
<Binding Path="DraggingRows.Count">
<Binding.Converter>
<dxgext:CountToVisibilityConverter Invert="True" />
</Binding.Converter>
</Binding>
</TextBlock.Visibility>
</TextBlock>
<ContentPresenter Name="rowInfoDragPresenter" Content="{Binding FirstDraggingObject}" ContentTemplate="{StaticResource rowInfoTemplate}">
<ContentPresenter.Visibility>
<Binding Path="DataContext.DraggingRows.Count" RelativeSource="{RelativeSource TemplatedParent}">
<Binding.Converter>
<dxgext:CountToVisibilityConverter Invert="True" />
</Binding.Converter>
</Binding>
</ContentPresenter.Visibility>
</ContentPresenter>
</StackPanel>
</Border>
</DataTemplate>
<DataTemplate x:Key="dropInfoTemplate">
<Border Name="border" BorderThickness="0 1 0 0" CornerRadius="0,0,5,5" Padding="12 8 24 10">
<Border.Background>
<Binding Path="DropTargetType">
<Binding.Converter>
<dx:EnumToObjectConverter DefaultValue="#FFF0F0F0">
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="None" Value="#FFEBADB4" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</Border.Background>
<Border.BorderBrush>
<Binding Path="DropTargetType">
<Binding.Converter>
<dx:EnumToObjectConverter DefaultValue="#FFC8C8C8">
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="None" Value="#FFFFD0D6" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</Border.BorderBrush>
<StackPanel>
<TextBlock Name="dropInfoText" FontWeight="Bold">
<TextBlock.Text>
<Binding Path="DropTargetType">
<Binding.Converter>
<dx:EnumToObjectConverter>
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="None" Value="Cannot drop here" />
<dx:EnumObjectProvider x:Key="DataArea" Value="Add rows" />
<dx:EnumObjectProvider x:Key="InsertRowsIntoGroup" Value="Move to group:" />
<dx:EnumObjectProvider x:Key="InsertRowsIntoNode" Value="Move to children collection:" />
<dx:EnumObjectProvider x:Key="InsertRowsAfter" Value="Insert after row:" />
<dx:EnumObjectProvider x:Key="InsertRowsBefore" Value="Insert before row:" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</TextBlock.Text>
<TextBlock.Foreground>
<Binding Path="DropTargetType">
<Binding.Converter>
<dx:EnumToObjectConverter DefaultValue="#FF949494">
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="None" Value="#FFB34242" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</TextBlock.Foreground>
</TextBlock>
<ContentPresenter Name="rowInfoPresenter" Content="{Binding DropTargetRow}" ContentTemplate="{StaticResource rowInfoTemplate}">
<ContentPresenter.Visibility>
<Binding Path="DataContext.DropTargetType" RelativeSource="{RelativeSource TemplatedParent}">
<Binding.Converter>
<dx:EnumToObjectConverter DefaultValue="Collapsed">
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="InsertRowsAfter" Value="Visible" />
<dx:EnumObjectProvider x:Key="InsertRowsBefore" Value="Visible" />
<dx:EnumObjectProvider x:Key="InsertRowsIntoNode" Value="Visible" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</ContentPresenter.Visibility>
</ContentPresenter>
<ItemsControl Name="groupInfoItemsControl" ItemsSource="{Binding GroupInfo}">
<ItemsControl.Visibility>
<Binding Path="DataContext.DropTargetType" RelativeSource="{RelativeSource TemplatedParent}">
<Binding.Converter>
<dx:EnumToObjectConverter DefaultValue="Collapsed">
<dx:EnumToObjectConverter.Values>
<dx:EnumObjectProvider x:Key="InsertRowsIntoGroup" Value="Visible" />
</dx:EnumToObjectConverter.Values>
</dx:EnumToObjectConverter>
</Binding.Converter>
</Binding>
</ItemsControl.Visibility>
<ItemsControl.ItemTemplate>
<DataTemplate>
<dxgext:NameTextControl x:Name="groupInfoControl" NameValue="{Binding FieldName}" TextValue="{Binding Value}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
<DataTemplate.Triggers>
<DataTrigger xmlns:interop="clr-namespace:System.Windows.Interop;assembly=PresentationFramework" Binding="{Binding Source={x:Static interop:BrowserInteropHelper.IsBrowserHosted}}" Value="True">
<Setter TargetName="border" Property="CornerRadius" Value="0,0,0,0" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Grid.Resources>
<dxg:GridControl Name="gridControl1" AutoPopulateColumns="True" ItemsSource="{Binding Items}">
<dxg:GridControl.View>
<dxg:TableView Name="tableView1" EditorShowMode="MouseUpFocused" ShowTotalSummary="True" />
</dxg:GridControl.View>
<i:Interaction.Behaviors>
<dxg:GridDragDropManager x:Name="gridDragDropManager">
<dxg:GridDragDropManager.DragElementTemplate>
<DataTemplate>
<dxgext:HintControl>
<StackPanel>
<ContentPresenter Name="dragInfo" Content="{Binding}" ContentTemplate="{StaticResource dragInfoTemplate}" />
<ContentPresenter Name="dropInfo" Content="{Binding}" ContentTemplate="{StaticResource dropInfoTemplate}" />
</StackPanel>
</dxgext:HintControl>
</DataTemplate>
</dxg:GridDragDropManager.DragElementTemplate>
</dxg:GridDragDropManager>
</i:Interaction.Behaviors>
</dxg:GridControl>
</Grid>
</Window>
WPF GridControl DragElementTemplate
最新推荐文章于 2024-02-04 07:42:08 发布