【问题标题】:WPF Drag drop Create a Layout for LocationsWPF 拖放为位置创建布局
【发布时间】:2018-02-20 01:46:34
【问题描述】:

我一直在为 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/ --> 是答案,但技术似乎过时了。

我的问题在这里;用户可以通过拖放对象或其他方式来安排位置和包含在该位置中的项目。我想在这张图片中做什么,你可以在这里看到:。 image2:https://ibb.co/jhip2c,用户将对象从对象列表(图像左侧)拖到右侧(用户控件、包装面板等)。为此,我也可以使用 DevExpress 工具。

我也尝试了 treeList 的解决方案,但这不是我导师的要求。

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

谢谢你..

【问题讨论】:

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


    【解决方案1】:

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

    来自 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>
    

    结果如下所示:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多