wpf - 将元素拖到边框时, Canvas 上的圆角消失

标签 wpf canvas drag-and-drop border rounded-corners

我有这个代码:

    <Window x:Class="WpfApplication8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ScrollViewer Background="#FFADB9CD"  >
            <Grid>
                <Border Name="mask" Height="{Binding ElementName=cnvsEtikett, Path=Height}" Width="{Binding ElementName=cnvsEtikett, Path=Width}" Background="White" CornerRadius="6"/>
                <Canvas Height="100" Name="cnvsEtikett" Width="200" Background="White" ClipToBounds="True">
                    <Canvas.OpacityMask>
                        <VisualBrush Visual="{Binding ElementName=mask}" />
                    </Canvas.OpacityMask>
                    <TextBlock Height="23.2"  Text="TextBlock" Canvas.Left="63" Canvas.Top="41" />
                </Canvas>
            </Grid>
        </ScrollViewer>
    </Grid>
</Window>

我希望 Canvas 具有圆角,直到我将文本 block 拖动到任一侧为止。然后角落消失。这是我程序中窗口的简单重新创建,我使用拖放操作来移动文本 block 。我真的需要那些圆角,但我完全不知道如何解决这个问题!

有什么想法吗??

编辑:当文本 block 移动到边缘时, Canvas 似乎被拉伸(stretch)了(因为角半径也发生了变化!)

最佳答案

刚刚想到另一个解决方案..

<Border ClipToBounds="True" CornerRadius="6" Background="White" Name="brdEtikett" Height="200" Width="200" >
    <Canvas Name="cnvsEtikett" Background="Transparent"  />
</Border>

在 Canvas 上将边框的背景设置为你想要的颜色,并使 Canvas 透明!!

这样您就不必在元素上放置填充或边距!

关于wpf - 将元素拖到边框时, Canvas 上的圆角消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983825/

相关文章:

javascript - 如何使拖放列表进行复制而不是移动列表项

javascript - 将 "dragstart"事件附加到 "mouseup"以获​​得可拖动体验

WPF TextBox lostfocus 作为附加属性

c# - 将 Button.CommandParameter 绑定(bind)到 MVVM 对象以使用相同的 ICommand 到不同的按钮

wpf - 将绑定(bind)数据传递到 DataGrid 中的用户控件

javascript - Cocoa WebView 中的 HTML5 canvas 绘图比 Safari 慢

javascript - 根据用户单击的位置旋转 Canvas 显示

c# - 使用 Background Worker 时丢失 UI 功能

java - 直接绘制到 Canvas 并使用 java 代码创建布局

ios - 是否可以使用 iOS 11 拖放在 UITableView 中一次重新排序多个项目/单元格?