I'm working on a UserControl (named DiagramControl) and have a problem. The UserControl's code is as follows:
<UserControl>
<Border>
<Grid>
<ScrollViewer x:Name="DesignerScrollViewer" ... />
...
<s:ZoomBox x:Name="zoomBox"
ScrollViewer="{Binding ElementName=DesignerScrollViewer}"/>
</Grid>
</Border>
</UserControl>
I am binding the ZoomBox (which has a scrollviewer DP) to DesignerScrollViewer. The method I use now works fine since the ZoomBox and DesignerScrollViewer are in the same XAML file.
What I would like to do however is to remove the ZoomBox from the control and define it in the window that uses the control. so for example something like:
<Grid>
<s:DiagramControl x:Name="DC" ... />
...
<s:ZoomBox ScrollViewer={Binding ElementName=DC,Path=DesignerScrollViewer}/>
</Grid>
I tried this but it doesn't work. How can I perform the binding that I need?
UPDATE:
I figured out what I needed to do. I added a ScrollViewer DP to DiagramControl and had it update when the DesignerScrollViewer's Layout was updated. so the following went into my DiagramControl code behind:
public static readonly DependencyProperty ScrollViewerProperty =
DependencyProperty.Register("ScrollViewer", typeof(ScrollViewer), typeof(DiagramControl), new UIPropertyMetadata(null, ScrollViewer_PropertyChanged));
public ScrollViewer ScrollViewer
{
get { return (ScrollViewer)GetValue(ScrollViewerProperty); }
set { SetValue(ScrollViewerProperty, value); }
}
private static void ScrollViewer_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
private void DesignerScrollViewer_LayoutUpdated(object sender, EventArgs e)
{
ScrollViewer = DesignerScrollViewer;
}
Now that the ScrollViewer DP had an update source i was able to bind to it from the window using the DiagramControl. Hope this helps someone in future.