0

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

  1. Access Zoombox from code-behind using FindTemplate and its name.
  2. Edit Zoombox source code and add a setter to Viewport.

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?

Denver
  • 151
  • 1
  • 6
  • Zoombox.Viewport is a read-only property that is internally updated by the Zoombox control. You can't simply set it. – Clemens Mar 04 '15 at 10:44
  • That is why I am trying to bind my property **to** it, I am not trying to change `Zoombox` `Viewport` property. – Denver Mar 04 '15 at 10:50
  • Then what stops you from doing that? A readonly dependency property can of course be used as the source property of a binding. – Clemens Mar 04 '15 at 10:52
  • `Zoombox` is a child of `MyControl`. I do not know the markup to bind `MyControl.MyViewport` property to `Zoombox.Viewport` property. – Denver Mar 04 '15 at 10:55
  • There is no such markup. You would usually call `Template.FindName("PART_Zoombox")` to get the Zoombox in code behind. See e.g [here](http://stackoverflow.com/a/18614227/1136211). – Clemens Mar 04 '15 at 11:12
  • That said, it would of course work in the XAML of a UserControl, where you would not have a ControlTemplate. – Clemens Mar 04 '15 at 11:16
  • Yes, I know that. The point of my answer was to ensure, that there is no way to do it, other than using code-behind. Thanks for the input. :) – Denver Mar 04 '15 at 11:20

0 Answers0