I have some problems when I try to bind the height and width of a window to properties in my view model. Here is a small sample app to illustrate the problem. This is the co
I am not sure about your specific implementation, but I just write an example that maybe could helpful.
XAML
Code
Class MainWindow
Public Shared ReadOnly WindowWidthProperty As DependencyProperty = _
DependencyProperty.Register("WindowWidth", _
GetType(Integer), GetType(MainWindow), _
New FrameworkPropertyMetadata(Nothing))
Public Shared ReadOnly WindowHeightProperty As DependencyProperty = _
DependencyProperty.Register("WindowHeight", _
GetType(Integer), GetType(MainWindow), _
New FrameworkPropertyMetadata(Nothing))
Public Property WindowWidth As Integer
Get
Return CInt(GetValue(WindowWidthProperty))
End Get
Set(ByVal value As Integer)
SetValue(WindowWidthProperty, value)
End Set
End Property
Public Property WindowHeight As Integer
Get
Return CInt(GetValue(WindowHeightProperty))
End Get
Set(ByVal value As Integer)
SetValue(WindowHeightProperty, value)
End Set
End Property
End Class
C# Code
public readonly DependencyProperty WindowWidthProperty = DependencyProperty.Register("WindowWidth", typeof(Double), typeof(MainWindow), new FrameworkPropertyMetadata());
public readonly DependencyProperty WindowHeightProperty = DependencyProperty.Register("WindowHeight", typeof(Double), typeof(MainWindow), new FrameworkPropertyMetadata());
public double WindowWidth {
get { return Convert.ToDouble(this.GetValue(WindowWidthProperty)); }
set { this.SetValue(WindowWidthProperty, value); }
}
public double WindowHeight {
get { return Convert.ToDouble(this.GetValue(WindowHeightProperty)); }
set { this.SetValue(WindowHeightProperty, value); }
}