C#C
C#2y ago
Elio

Access dependency property from a viewmodel WPF

HI, i'm using WPF and MVVM pattern. i've created a DependencyProperty IsEditable and how do i access this one from my viewmodel to bind it to CanExecute for my command.

public class ListingUserControl : UserControl
{
    #region Properties
    public bool IsEditable
    {
        get => (bool)GetValue(IsEditableProperty);
        set => SetValue(IsEditableProperty, value);
    }

    public static readonly DependencyProperty IsEditableProperty =
        DependencyProperty.Register(
        "IsEditable",
        typeof(bool),
        typeof(ListingUserControl),
        new PropertyMetadata(true));
    #endregion

} 

        private bool CanExecuteCommand() { return IsEditable; }
Was this page helpful?