将画布停靠在其父对象中

ser*_*hio 3 wpf canvas dock

如何将画布“停靠”在其父级中?

我有一个UserControl,其中包含一个画布。

<UserControl x:Class="MyUC"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d"              
         d:DesignHeight="300" d:DesignWidth="300">
    <MyCanvas x:Name="myCanvas" 
        Height="???" 
        Width="???{Binding RelativeSource={RelativeSource TemplatedParent}}" >
    </MyCanvas>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

我在其中使用此自定义画布的WidthHeight属性。并且需要始终将这些属性“绑定”到父容器。

use*_*134 5

尝试这个

Width="{Binding RelativeSource={RelativeSource FindAncestor, 
                                               AncestorType=UserControl, 
                                               AncestorLevel=1},
                Path=ActualWidth}"
Run Code Online (Sandbox Code Playgroud)

身高也一样