如何将画布“停靠”在其父级中?
我有一个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)
我在其中使用此自定义画布的Width
和Height
属性。并且需要始终将这些属性“绑定”到父容器。
尝试这个
Width="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType=UserControl,
AncestorLevel=1},
Path=ActualWidth}"
Run Code Online (Sandbox Code Playgroud)
身高也一样
归档时间: |
|
查看次数: |
5565 次 |
最近记录: |