Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4038466
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:28:35+00:00 2026-05-20T12:28:35+00:00

I am attempting to bind my ViewModel’s IsInInputMode property to a Dependency Property in

  • 0

I am attempting to bind my ViewModel’s IsInInputMode property to a Dependency Property in a UserControl. I am setting the UserControl’s DataContext to an instance of my ViewModel and all my XAML based bindings are working correctly. I need a code-behind solution to create this binding. I’ve tried a few things (at the bottom of the post) which have not worked.

I’m not getting any exceptions logged to the Output window either, which is where I’ve been told to look for Binding based exceptions.

I asked this similar question, on binding a Dependency Property in a UserControl through XAML — I was told this is not possible, so I’m looking for a code-behind solution.

The ViewModel looks like this:

class AddClientViewModel : ViewModelBase
{
    private Boolean _isInInputMode;
    public Boolean IsInInputMode
    {
        get { return _isInInputMode; }
        set
        {
            _isInInputMode = value;
            OnPropertyChanged("IsInInputMode");
        }
    }

    public ICommand Cancel
    {
        get { return new RelayCommand(parm => { IsInInputMode = false; }); }
    }
}

The Cancel command is successfully being data bound to a Button’s Command through XAML.

The Dependency Property in the UserControl looks like this:

    public bool IsInInputMode
    {
        get { return (bool)GetValue(IsInInputModeProperty); }
        set { SetValue(IsInInputModeProperty, value); }
    }
    public static readonly DependencyProperty IsInInputModeProperty =
        DependencyProperty.Register("IsInInputMode", typeof(bool), typeof(AddClientView), new UIPropertyMetadata(new PropertyChangedCallback(_OnIsInInputModePropertyChanged)));

    private static void _OnIsInInputModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var mycontrol = d as AddClientView;

        bool oldValue = (bool)e.OldValue;
        bool newValue = (bool)e.NewValue;

        if (null != mycontrol && oldValue != newValue)
        {
            mycontrol._OnIsInInputModeChanged(oldValue, newValue);
        }
    }

    private void _OnIsInInputModeChanged(bool oldValue, bool newValue)
    {
        if (newValue)
        {
            VisualStateManager.GoToState(this, "InputState", false);
        }
        else
        {
            VisualStateManager.GoToState(this, "HiddenState", false);
        }
    }

The Binding in the Constructor of my UserControl has had a few iterations.

First Try:

    public AddClientView()
    {
        InitializeComponent();
        SetBinding(IsInInputModeProperty, "IsInInputMode");
    }

Second Try:

    public AddClientView()
    {
        InitializeComponent();

        var b = new Binding();
        b.Source = this.DataContext;
        b.Path = new PropertyPath("IsInInputMode");
        b.Mode = BindingMode.TwoWay;
        b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        BindingOperations.SetBinding(this, IsInInputModeProperty, b);
    }

Neither of these “fail” with a compiler or runtime error; but when the IsInInputMode property changes in the ViewModel, the Dependency Property never updates, and the two even handlers there are never called.

As an additional note, the ViewModel has a few ICommand properties, which are being successfully bound to buttons in the UserControl via XAML — so I know the DataContext binding correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:28:36+00:00Added an answer on May 20, 2026 at 12:28 pm

    Turns out it was a PEBKEC issue — I had a default value set somewhere, so OnNotifyPropertyChanged never got called, as such it appeared that the binding was broken.

    I bound my boolean to a checkbox on the View, and using the UI control to change the value forced my animations to change, the correct code-behind binding was my first try:

    SetBinding(IsInInputModeProperty, "IsInInputMode");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to bind a WPF textbox's Maxlength property to a known constant
I'm attempting to bind a DependancyProperty in one of my usercontrols to the Width
Without attempting to bind it
Attempting to insert an escape character into a table results in a warning. For
Attempting to print out a list of values from 2 different variables that are
Attempting to deploy a MOSS solution to a UAT server from dev server for
When attempting to compile my C# project, I get the following error: 'C:\Documents and
When attempting to call functions in math.h , I'm getting link errors like the
When attempting to understand how a SQL statement is executing, it is sometimes recommended
Does attempting to develop some sort of game, even just as a hobby during

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.