WPF拖放创建位置布局

时间:2018-02-20 01:46:35

标签: c# wpf drag-and-drop devexpress draggable

我一直在担心wpf拖放的想法。到目前为止,我尝试了以下示例列表,但它并没有帮助我。

https://codeblitz.wordpress.com/2009/06/26/wpf-itemscontrol-drag-drop-behavior/

https://github.com/dotnet/docs/tree/master/samples/snippets/csharp/VS_Snippets_Wpf/DragDropWalkthrough/CS

https://www.codeproject.com/Articles/17266/Drag-and-Drop-Items-in-a-WPF-ListView

http://www.dotnetlead.com/ - >这是答案,但技术似乎已经过时了。

我的问题在这里;用户可以通过拖放对象或其他任何内容来安排该位置中包含的位置和项目。我想在这张图片中做些什么,你可以在这里看到:wpf drag drop example image。 image2:https://ibb.co/jhip2c,用户将对象从对象列表(图像中的左侧)拖动到右侧(usercontrol,换行面板等)。为此,我也可以使用DevExpress工具。

解决方案我也尝试了treeList,但它不是我教师的请求。

我也期待着任何例子。所以,请留下评论。

谢谢..

1 个答案:

答案 0 :(得分:0)

由于您可以访问DevExpress控件,因此我建议您使用LayoutControl。它支持grouping, tabs, and handles label positioning for you。它还允许用户输入customization mode,其中他们可以使用拖放添加,删除和重新排列项目。根据您提供的模型,这可能是您的导师要求您做的,因为机制看起来相同:

Screenshot

在DevExpress的帮助库中,下面是使用此系统创建包含独立字段,组和标签的非平凡布局的example

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
        Height="300"
        Width="572">
  <Grid>
    <lc:LayoutControl Orientation="Vertical">
      <lc:LayoutGroup Orientation="Horizontal">
        <lc:LayoutGroup Orientation="Vertical">
          <lc:LayoutGroup Orientation="Horizontal" View="GroupBox" Header="Group 1" IsCollapsible="True">
            <lc:LayoutItem Label="Item 1:" VerticalAlignment="Stretch">
              <TextBox/>
            </lc:LayoutItem>
            <lc:LayoutGroup Orientation="Vertical" lc:LayoutControl.AllowHorizontalSizing="True">
              <lc:LayoutItem Label="Item 2:" VerticalAlignment="Stretch">
                <TextBox/>
              </lc:LayoutItem>
              <lc:LayoutItem Label="Item 3:" VerticalAlignment="Stretch">
                <TextBox/>
              </lc:LayoutItem>
            </lc:LayoutGroup>
          </lc:LayoutGroup>
          <lc:LayoutItem Label="Item 4:"  VerticalAlignment="Stretch" lc:LayoutControl.AllowVerticalSizing="True">
            <TextBox/>
          </lc:LayoutItem>
        </lc:LayoutGroup>
        <lc:LayoutGroup View="Tabs" lc:LayoutControl.AllowHorizontalSizing="True">
          <lc:LayoutGroup Header="Tab 1" Orientation="Vertical">
            <lc:LayoutItem Label="Item 5:">
              <TextBox/>
            </lc:LayoutItem>
            <lc:LayoutItem Label="Item 6:" VerticalAlignment="Stretch">
              <TextBox/>
            </lc:LayoutItem>
          </lc:LayoutGroup>
          <lc:LayoutGroup Header="Tab 2" Orientation="Vertical">
            <lc:LayoutItem Label="Item 7:">
              <TextBox/>
            </lc:LayoutItem>
            <lc:LayoutItem Label="Item 8:">
              <TextBox/>
            </lc:LayoutItem>
          </lc:LayoutGroup>
        </lc:LayoutGroup>
      </lc:LayoutGroup>
      <lc:LayoutGroup Orientation="Horizontal">
        <lc:LayoutItem Label="Item 9:" HorizontalAlignment="Left">
          <TextBox Width="100"/>
        </lc:LayoutItem>
        <lc:LayoutItem Label="Item 10:">
          <TextBox/>
        </lc:LayoutItem>
        <lc:LayoutItem Label="Item 11:" HorizontalAlignment="Right">
          <TextBox Width="100"/>
        </lc:LayoutItem>
      </lc:LayoutGroup>
    </lc:LayoutControl>
  </Grid>
</Window>

结果如下:

Screenshot of Example Results