Hello!
I am creating a custom control MyControl
, using Zoombox
control from Extended WPF Toolkit. Zoombox
has a Viewport
property. I created the same property MyViewport
in MyControl
and I need to bind it to Zoombox
's Viewport
property. I could bind from Zoombox
to MyControl
, but Viewport
in Zoombox
is defined as readonly DependencyProperty
. I know two ways to do that (listed below), but I would like to avoid them.
Two ways of doing it
- Access
Zoombox
from code-behind usingFindTemplate
and its name. - Edit
Zoombox
source code and add a setter toViewport
.
Generic.xaml file of MyControl
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyControlLibrary"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit">
<Style TargetType="{x:Type local:MyControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyControl}">
<xctk:Zoombox x:Name="PART_Zoombox"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="MyViewport"
Value={Binding ElementName=PART_Zoombox, Path=Viewport}
/>
</Style>
</ResourceDictionary>
So, how can I do it using only XAML?