I have a requirement of passing reference of control to another custom control.
I created a custom control which contains a dependency property associateDatagridProperty
public static readonly DependencyProperty
AssociatedDataGridProperty = DependencyProperty.Register(
"AssociatedDatagrid",
typeof(DataGrid),
typeof(CustomControl),
new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)
);
public Datagrid AssociatedDatagrid
{
get { return (Datagrid )base.GetValue(AssociatedDataGridProperty); }
set { base.SetValue(AssociatedDataGridProperty, value); }
}
In the XAML I'm assigning Value like this
<Datagrid x:name=ClientGrid />
Here Datagrid is Microsoft WPF toolkit datagrid
<CustomControl x:Name="DatagridPaging"
Canvas.Left="24"
Canvas.Top="236"
AssociatedDatagrid="{Binding ElementName=clientsGrid ,Path=Name}">
When I try to access the value of AssociatedDatagrid property it always shows null
Can anyone tell me the right way of doing it?
Here is the code :
First element which will be referenced in the second one :
<Label x:Name="aGivenNameLabel" Content="kikou lol"/>
The second element :
<ContentControl Content={Binding ElementName=aGivenNameLabel}" />
Good luck !
You don't need Path=Name
in your Binding
. What you end up doing here instead is passing the value of the Name
property of the DataGrid
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With