I have a UserControl called BranchFilter, with the following property:
private int? _branchId; public int? LocalBranchId { get { return _branchId; } set { SetProperty(ref _branchId, value); OnBranchChanged(); } } In the same control, I register a dependency property so that I can bind the branch id to a viewmodel:
public static readonly DependencyProperty BranchIdProperty = DependencyProperty.Register(nameof(LocalBranchId), typeof(int?), typeof(BranchFilter), new UIPropertyMetadata(null)); And when I try and access this property, without even binding it, in a view, like so:
<controls:BranchFilter Grid.Row="0" BranchId="0"> <i:Interaction.Triggers> <i:EventTrigger EventName="BranchChanged"> <i:InvokeCommandAction Command="{Binding LoadItems}" /> </i:EventTrigger> </i:Interaction.Triggers> </controls:BranchFilter> I get the compile errors:
The member "BranchId" is not recognized or is not accessible.
The property 'BranchId' was not found in type 'BranchFilter'.
The property 'BranchId' does not exist in XML namespace 'clr-namespace:ApptBook.Client.Modules.Common.Controls'
I have followed every example, but they're all the same, for adding the dependency property, but everything I have tried has failed. What could be wrong with something so simple?
propdpcode-snippet to generate dependency property properly.propdpand hitTabkey twice.GetValueandSetValuein its get and set accessors. You can not declare a dependency property that wraps a CLR property. See Custom Dependency Properties.