Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dock a Canvas in its parent

Tags:

canvas

wpf

dock

How can I "dock" a canvas in its parent?

I have a UserControl that contains a canvas inside.

<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>

I use Width and Height properties of this custom canvas inside. And need that that properties be always "bind" to the parent Container.

like image 816
serhio Avatar asked May 14 '26 13:05

serhio


1 Answers

Try this

Width="{Binding RelativeSource={RelativeSource FindAncestor, 
                                               AncestorType=UserControl, 
                                               AncestorLevel=1},
                Path=ActualWidth}"

Same goes for height

like image 148
user109134 Avatar answered May 16 '26 02:05

user109134



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!