I am trying to bind ChildWindow Height
property to my viewmodel property , but I think it only reads VM value on first load and doesn't change size when VM changes & notifies about the change. In debugger I see that it goes into Height getter once, further notifications don't change ChildWindow size..
I think it should be bindable so I am wondering whether some issue exists here or I am doing some mistake?
Sounds like one time binding, but its oneway..
Height="{Binding WindowHeight,Mode=OneWay}"
Further investigation shows that when we change binding to Mode=TwoWay
and add an empty setter it begins to behave as expected. But that doesn't explain the reason why OneWay binding doesn't work. Also value that is passed to setter is equal to my whole application height, not just childwindow that is obviously supposed to be smaller.
The most strange thing with this whole situation is the following:
Also this value is passed to setter 4 consecutive times everytime after a getter is called (see
count++
that is used to count that).
It is fired before dialog is actually shown, and it always goes in sequence get,set,set,set,set
Code for view model is super simple. Nowhere in code anyone is using ChildWindow Height, its only set in its xaml binding as shown above.
private int count = 0;
public int WindowHeight
{
get { return IsDefaultMode? DEFAULT_HEIGHT : SPECIAL_HEIGHT; }
set {count++; }
}
My inheriting Childwindow class contains like 5 strings of text none of which affect Height in any way.
Notification about WindowHeight is not fired by WindowHeight property (as seen in code) , its fired by Mode property. Couldve been a converter around mode but its currently implemented this way cause I am not sure a special converter with a couple of magic values for this situation is a better approach.
oks . mode setter code:
public bool IsSpecialMode
{
get { return m_IsSpecialMode; }
set
{
if (m_IsSpecialMode!= value)
{
m_IsSpecialMode= value;
NotifyPropertyChanged("IsSpecialMode");
NotifyPropertyChanged("WindowHeight");
}
}
}