I have a user control with a slider called MySlider within. I need to bind its value to the parent windows Datagrid:
<DataGrid.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=MySlider, Path=Value}"
ScaleY="{Binding ElementName=MySlider, Path=Value}" />
</DataGrid.LayoutTransform>
I cannot access it by its Element Name, because it is inside of the UserControl (lets call it usercontrol).
I have already tried creating a public property in usercontrol:
public partial class usercontrol: UserControl
{
public double SliderValue { get { return (double)MySlider.Value; } }
}
and binding it to the DataGrid (given x:Name to the usercontrol):
<DataGrid.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=usercontrolName, Path=SliderValue}"
ScaleY="{Binding ElementName=usercontrolName, Path=SliderValue}" />
</DataGrid.LayoutTransform>
PROBLEM SOLVED thanks to GazTheDestroyer, see below (1) In MyUserControl.xaml at UserControl declaration:
<UserControl x:Class="..."
Name="root">
(2) In MyUserControl.xaml at Slider:
<Slider Value="{Binding SliderValue, ElementName=root}"/>
(3) Other parts: see answer of GazTheDestroyer
UserControl
and theDataGrid
located in your window. Please post your XAML markup. – mm8