0

In the usercontrol TimeTableView.xaml there is a child usercontrol of type ViewControl. Via a slider in TimeTableView I wish to affect the size of a grid in the ViewControl. Following similar SO questions I've put a DependencyProperty on the ViewControl and bound that within both usercontrols. However, I get a binding error pertaining to the binding in ViewControl: "ZoomValue Property not found on object of type ViewControl" Must be a silly error somewhere, but where is it? I've tried variation on this for example ...ScaleX="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ViewControl}}... but same problem

TimeTableView.xaml

...
<Slider Name="Slider" Minimum="0.5" Maximum="2" Value="1" Width="100"/>
...
<local:ViewControl x:Name="MainSectionView" DataContext="{Binding Path=MainViewDataContext}" 
local:ZoomHost.ZoomValue="{Binding ElementName=Slider, Path=Value}"/>
...

ViewControl.xaml
...

...
<Grid>
<Grid.RenderTransform>
<ScaleTransform ScaleX="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=ZoomValue}"></ScaleTransform>
</Grid.RenderTransform>
...
</Grid>

ZoomHost

public class ZoomHost
{
  public static readonly DependencyProperty ZoomValueProperty = 
  DependencyProperty.RegisterAttached("ZoomValue", typeof(float), typeof(ZoomHost));

  public static float GetZoomValue(ViewControl vwc)
  {
    return (float)vwc.GetValue(ZoomValueProperty);
  }
  public static void SetZoomValue(ViewControl vwc, float value)
  {
    vwc.SetValue(ZoomValueProperty, value);
  }
} 
user3486991
  • 451
  • 6
  • 14
  • 1
    Try `Path=(local:ZoomHost.ZoomValue)`. See here: https://stackoverflow.com/a/5832247/1136211 – Clemens Nov 23 '21 at 22:09
  • Thanks! this worked: ScaleX="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ViewControl}} Path=(local:ZoomHost.ZoomValue)}"/> Have to agree with a comment on that link, WPF Syntax is really arcane sometimes. I have never seen those brackets used like that in .xaml before, and don't know how I would have found out they're necessary, apart from SO and your answer! – user3486991 Nov 23 '21 at 23:06
  • It is well documented in [PropertyPath XAML Syntax](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/propertypath-xaml-syntax?view=netframeworkdesktop-4.8). I would not call it arcane, it just reflects the complexity of things you can do with dependency properties. – Clemens Nov 24 '21 at 07:25

0 Answers0