2015-05-13 46 views
0

我有一個擴展Window類的類VirtualKeyboard。 我有另一個類 - 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"); 

而這裏的通知方法:

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; 

這段代碼是在視圖模型類,從中KeyboardViewModel延伸,並實現了INotifyPropertyChanged接口。

我的問題是這樣的:

當我按一下按鈕,KeyboardWindowHeight得到改變,通知被調用,但是窗口高度保持不變。爲什麼會發生這種情況,以及如何解決它?

+0

您是否嘗試過KeyboardWindowHeight屬性綁定到和了minHeight MaxHeight,以及高度? –

回答

0
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中高度財產應工作