wpf中的绑定窗口高度
我有一个类VirtualKeyboard,它扩展了Window类。 我有另一个类-EnglishVirtualKeyboard,它是从VirtualKeyboard类扩展而来的 这是我在EnglishVirtualKeyboard.xaml中的内容:wpf中的绑定窗口高度,wpf,xaml,data-binding,inotifypropertychanged,Wpf,Xaml,Data Binding,Inotifypropertychanged,我有一个类VirtualKeyboard,它扩展了Window类。 我有另一个类-EnglishVirtualKeyboard,它是从VirtualKeyboard类扩展而来的 这是我在EnglishVirtualKeyboard.xaml中的内容: <vk:VirtualKeyboard x:Class="Hurst.VirtualKeyboard.EnglishVirtualKeyboard" xmlns="http://schemas.microsoft.com/winfx/2006
<vk:VirtualKeyboard x:Class="Hurst.VirtualKeyboard.EnglishVirtualKeyboard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:vk="clr-namespace:Hurst.VirtualKeyboard"
xmlns:vm="clr-namespace:Hurst.VirtualKeyboard.ViewModels"
DataContext="{DynamicResource keyboardViewModel}"
Height="{Binding KeyboardWindowHeight}" Width="1280" d:DesignHeight="300" d:DesignWidth="710"
x:Name="VK">
<vk:VirtualKeyboard.Resources>
<ObjectDataProvider x:Key="keyboardViewModel" ObjectType="{x:Type vm:KeyboardViewModel}" />
</vk:VirtualKeyboard.Resources>
下面是Notify方法:
public void Notify([CallerMemberName] string propertyName = "")
{
this.VerifyProperty(propertyName);
// Make a copy of the PropertyChanged event first, before testing it for null,
// because another thread might change it between the two statements.
var copyOfPropertyChangedEvent = PropertyChanged;
if (copyOfPropertyChangedEvent != null)
{
// Get the cached event-arg.
var args = GetPropertyChangedEventArgs(propertyName);
copyOfPropertyChangedEvent(this, args);
}
this.AfterPropertyChanged(propertyName);
}
public event PropertyChangedEventHandler PropertyChanged;
此代码位于ViewModel类中,KeyboardViewModel从该类扩展并实现INotifyPropertyChanged接口
我的问题是:
当我点击按钮时,KeyboardWindowHeight被更改,Notify被调用,但窗口高度保持不变。为什么会发生这种情况以及如何解决
public bool Button_clicked
{
get
{
return _button_clicked;
}
set
{
_button_clicked = value;
if (value)
Win_height = 500;
else
Win_height = 300;
onPropertyChanged("Button_clicked");
}
}
将Win_height属性绑定到xaml中的height属性应该可以工作您是否尝试将KeyboardWindowHeight属性绑定到MinHeight和MaxHeight以及height?
public bool Button_clicked
{
get
{
return _button_clicked;
}
set
{
_button_clicked = value;
if (value)
Win_height = 500;
else
Win_height = 300;
onPropertyChanged("Button_clicked");
}
}