C# 帆布堆放问题

C# 帆布堆放问题,c#,wpf,canvas,C#,Wpf,Canvas,我在画布上有一些内容的边框和一行。边框+内容是可拖动的,行会随着边框移动而更新。我的问题是,该行位于边界的顶部,因此在某些情况下它会阻止我的内容。我尝试过设置ZIndex,并在XAML中更改了它们的顺序,但没有任何效果。我猜这是因为行在改变形状时不断被渲染,并且出于某种原因输出到顶部的屏幕。有办法吗 我的一些代码 XAML <Canvas x:Name="canvas" MouseDown="Canvas_MouseDown" MouseUp

我在画布上有一些内容的边框和一行。边框+内容是可拖动的,
会随着边框移动而更新。我的问题是,该行位于边界的顶部,因此在某些情况下它会阻止我的内容。我尝试过设置ZIndex,并在XAML中更改了它们的顺序,但没有任何效果。我猜这是因为
在改变形状时不断被渲染,并且出于某种原因输出到顶部的屏幕。有办法吗

我的一些代码

XAML

<Canvas x:Name="canvas"
            MouseDown="Canvas_MouseDown"
            MouseUp="Canvas_MouseUp"
            MouseMove="Canvas_MouseMove">
            <Border BorderBrush="Aqua" BorderThickness="3" Padding="3" Name="bdr"
Background="{StaticResource GradientBackground}" Canvas.ZIndex="99"
                MouseLeftButtonDown="MouseLeftBtnDown">
                <Border.RenderTransform>
                    <TranslateTransform />
                </Border.RenderTransform>
    <button/>
            </Border>
        </Canvas>
        <Polygon
            Canvas.ZIndex="98"
            Name="SpeechPoly"
            Stroke="Aqua" 
            StrokeThickness="2"
            Fill="{StaticResource GradientBackground}">
        </Polygon>

掷骰子的工作是确定线在边界上的位置(即右/左手侧、顶部/底部),并在边界周围移动

已更新

if (p.X > myPoints[0].X)//right
{
    if (p.Y + bdr.ActualHeight> myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X, p.Y + 50));
        myPoints.Add(new Point(p.X, p.Y + 25));
    }
    else//higher
    {
        myPoints.Add(new Point(p.X, p.Y + bdr.ActualHeight- 50));
        myPoints.Add(new Point(p.X, p.Y + bdr.ActualHeight - 25));
    }
}
else if (p.X + bdr.ActualWidth > myPoints[0].X)//Middle
{
    if (p.Y + bdr.ActualHeight > myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2) + 25, p.Y));
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2), p.Y));
    }
    else if (p.Y + bdr.ActualHeight < myPoints[0].Y)//higher
    {
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2) + 25, p.Y + bdr.ActualHeight));
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2), p.Y + bdr.ActualHeight));
    }
}
else//left
{
    if (p.Y > myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 50));
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 25));
    }
    else//higher
    {
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 50));
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 25));
    }
}
if(p.X>myPoints[0].X)//右
{
如果(p.Y+bdr.ActualHeight>myPoints[0].Y)//更低
{
添加(新点(p.X,p.Y+50));
添加(新点(p.X,p.Y+25));
}
其他//更高
{
添加(新点(p.X,p.Y+bdr.ActualHeight-50));
添加(新点(p.X,p.Y+bdr.ActualHeight-25));
}
}
如果(p.X+bdr.ActualWidth>myPoints[0].X)//中间
{
如果(p.Y+bdr.ActualHeight>myPoints[0].Y)//更低
{
添加(新点(p.X+(bdr.ActualWidth/2)+25,p.Y));
添加(新点(p.X+(bdr.ActualWidth/2),p.Y));
}
否则如果(p.Y+bdr.ActualHeightmyPoints[0].Y)//更低
{
添加(新点(p.X+bdr.ActualWidth,p.Y+50));
添加(新点(p.X+bdr.ActualWidth,p.Y+25));
}
其他//更高
{
添加(新点(p.X+bdr.ActualWidth,p.Y+50));
添加(新点(p.X+bdr.ActualWidth,p.Y+25));
}
}
解决方案


必须将我的
放在与边框相同的画布中。现在看来很明显。。。谢谢文森特

您可能有兴趣阅读以下内容:嗯,尝试应用最上面的答案,但他们列出的方法使用了一个参数,但方法调用没有提供一个参数:/your polygon确实是一个依赖对象,您可以使用提供的函数找到它的内容呈现者吗?ooooooooppps为您提供!!!您为多边形放置了Canvas.ZIndex,而它不在画布中!!!lmao,我在一个阶段把它放在画布上,忘了移除ZIndex,但我试着把它们都放在同一个画布上(我以前没试过),效果很好!再次感谢你。
if (p.X > myPoints[0].X)//right
{
    if (p.Y + bdr.ActualHeight> myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X, p.Y + 50));
        myPoints.Add(new Point(p.X, p.Y + 25));
    }
    else//higher
    {
        myPoints.Add(new Point(p.X, p.Y + bdr.ActualHeight- 50));
        myPoints.Add(new Point(p.X, p.Y + bdr.ActualHeight - 25));
    }
}
else if (p.X + bdr.ActualWidth > myPoints[0].X)//Middle
{
    if (p.Y + bdr.ActualHeight > myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2) + 25, p.Y));
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2), p.Y));
    }
    else if (p.Y + bdr.ActualHeight < myPoints[0].Y)//higher
    {
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2) + 25, p.Y + bdr.ActualHeight));
        myPoints.Add(new Point(p.X + (bdr.ActualWidth / 2), p.Y + bdr.ActualHeight));
    }
}
else//left
{
    if (p.Y > myPoints[0].Y)//lower
    {
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 50));
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 25));
    }
    else//higher
    {
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 50));
        myPoints.Add(new Point(p.X + bdr.ActualWidth, p.Y + 25));
    }
}