У меня есть класс VirtualKeyboard, который расширяет класс Window. У меня есть еще один класс - EnglishVirtualKeyboard, который простирается от класса VirtualKeyboard.Высота окна привязки в wpf
Это то, что я имею в EnglishVirtualKeyboard.xaml:
<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>
KeyboardWindowHeight свойство в классе KeyboardViewModel.
Когда я нажимаю на одну кнопку с клавиатуры, я хочу изменить высоту окна. Вот мой код:
if (buttonPressed)
{
KeyboardWindowHeight = 400;
}
else
{
KeyboardWindowHeight = 485;
}
Notify("KeyboardWindowHeight");
А вот метод 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 называется, но высота окна остается неизменным. Почему это происходит и как это исправить?
Вы пытались связать KeyboardWindowHeight свойства MinHeight и MaxHeight, а также высота? –