【问题标题】:Gong drag and drop: drag effect border does not fit element锣拖拽:拖拽效果边框不适合元素
【发布时间】:2021-02-12 08:37:03
【问题描述】:

使用锣拖放框架,可以得到一个拖动效果,这是一个简单的边框围绕可能的droptarget。

但是,在我的情况下,由于某种原因,此边框不适合实际元素,如下所示:

我已经尝试更改放置目标的不同 xaml 元素的背景颜色,以了解某些元素是否更大(但隐藏),但找不到。

我猜这个问题是由于使用了我使用的视图框,因为这些放置目标的大小是动态的并且可以缩放。

这是放置目标的xaml代码:

<Border BorderThickness="{Binding PlatformBorderThickness}"  dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{StaticResource CustomDropHandler}" >
    <Border.BorderBrush>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="Black" Offset="0.1"/>
            <GradientStop Color="Transparent" Offset="0.1"/>
            <GradientStop Color="Transparent" Offset="0.9"/>
            <GradientStop Color="Black" Offset="0.9"/>
            <GradientStop Color="Black" Offset="1"/>
        </LinearGradientBrush>
    </Border.BorderBrush>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="10*"/>
        </Grid.RowDefinitions>


        <Viewbox Grid.Column="0" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="1" HorizontalAlignment="Left">
            <TextBlock Text="{Binding Equipment.Name, FallbackValue='Please add a device!'}" FontWeight="Bold"/>
        </Viewbox>
        <Viewbox Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="0" Grid.RowSpan="1" Stretch="Uniform"  HorizontalAlignment="Right">
            <Button  Command="{Binding DeleteButtonClick}" Background="Transparent" BorderThickness="0"
            Margin="0" Padding="0">
                <Image Source="/Resources/Cancel.ico"/>
            </Button>
        </Viewbox>

        <Viewbox Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" Grid.RowSpan="1" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Uniform" Margin="2">
        <DataGrid Width="200" Height="135" HeadersVisibility="None" RowBackground="Transparent" BorderThickness="0"
                  ItemsSource="{Binding Equipment.Settings}" SelectionMode="Single" AutoGenerateColumns="False" GridLinesVisibility="Vertical" CanUserAddRows="False"
                  GotFocus="DataGrid_GotFocus" Name="DutInfoGrid" >
            <DataGrid.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
            </DataGrid.Resources>
            <DataGrid.Background>
                <ImageBrush ImageSource="{Binding Equipment.ImagePath, FallbackValue={StaticResource AddItemImage}, TargetNullValue={StaticResource AddItemImage}}"
                                Stretch="Fill" Opacity="0.25"/>
            </DataGrid.Background>
            <DataGrid.Columns>
                <DataGridTemplateColumn >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Name="DutInfoGridRemoveButton" Background="Transparent" BorderThickness="0" Margin="0" Padding="0" Height="15"
                                    Command="{Binding Path=DataContext.RemoveClick, RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
                                    CommandParameter="{Binding}">
                                <Image Source="/Resources/Trash.ico"/>
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn  Binding="{Binding Items[3].Value}"/>
                <DataGridTextColumn  Binding="{Binding Items[6].Value}" />
            </DataGrid.Columns>
        </DataGrid>
        </Viewbox>
    </Grid>
</Border>

编辑:

经过进一步测试,我发现如果我删除数据网格周围的 ViewBox 元素,问题就消失了。任何想法,为什么 ViewBox 会导致此问题以及如何解决?

【问题讨论】:

  • 将每个控件包装到 Viewbox 中是没有意义的。例如,默认情况下 Button 会拉伸以占用所有可用空间。适当的维度属性和适当的面板将足以获得响应式布局。不要将所有内容都包装到 Viewbox 中。
  • @BionicCode 您可能对按钮周围的 ViewBox 是正确的,但是我已经尝试了几种如何将控件包装到 ViewBoxes 中的配置(从根本不使用到将整个边框包装成一个) 并将每个控件包装到它自己的 ViewBox 中是唯一的一个,它给出了所需的行为。这是因为用户可以在运行时调整所有内容的大小,并且它也是可缩放的。无论如何,造成问题的 ViewBox 是包装数据网格的问题,这里的问题是,导致这种行为的原因仍然存在。
  • 我很确定这是GongSolutions.Wpf.DragDrop NuGet 中的一个错误。很可能它在OnRender 文件中DropTargetHighlightAdorner - link to source code

标签: wpf xaml drag-and-drop


【解决方案1】:

您可能应该切换到操作文件,然后将 jQuery 与引用拖放的 XML 代码交换并使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多