views:

34

answers:

1

I want a 1-time databind between a checkbox (IsChecked propety) in a childWindow and a nested member variable in it's DataContext object, such that only the initial IsChecked property is set by the member variable. The member variable (binding source) is not INotifyPropertyChanged or marked as a DependencyProperty- but I think that is ok b/c I only want it to be evaluated once- when it gets its initial value.

Binding (in testChildWindow.xaml):

<CheckBox Content="Show Username?" Name="cbShowUser" IsChecked="{Binding Path=User.showUser}"/>

Setting DataContext (in parent window code-behind):

  testChildWindow dlgBox = new testChildWindow();
  dlgBox.DataContext = (this.DataContext as IAssignDlgViewModel).AssignVM("defaultChildWindow");
  dlgBox.Show();

Data Context/Member variable:

public class testChildWindowViewModel : IDlgViewUpdate 
{
  public User
  ...
}

public class User 
{
  public bool showUser;
  public User()
  {
    showUser = true;
  }
  ...
}

If I make the Vm's binding source property (showUser) a dependency property at the (non-nested) testChildWindowViewModel, then the binding works. But all other combinations seem to fail.

Why must it be a dependency (or INotifyPropertyChanged?) property for a 1-time binding?

Why can't I get it to work at a nested level?

Thanks!!!

A: 

Ah, looking at the Output window during the binding answered the question for me. The problem was that User was not a property. Changed it to an auto property and the binding works just right now.

skj