2016-02-22 37 views
3

我新的編程和我有我的傳球類,我在<Window.Resources>創造了XAML作爲命令參數的困難。不能一類作爲參數傳遞給命令

<Window.Resources> 
     <local:RegisterWindowViewModel x:Key="RegViewModel"/> 
     <local:RegisterValidationConverter x:Key="RegValid"/> 
     <local:UsersViewModel x:Key="UVM"/> 
    </Window.Resources> 

下面是用命令結合

<Button Name="signupButton" DataContext="{StaticResource UVM}" 
      Height="50" Width="150" BorderBrush="Black" BorderThickness="2" 
      FontSize="20" FontWeight="SemiBold" 
      Style="{StaticResource AccentedSquareButtonStyle}" 
      Command="{Binding GetRegisterItemCommand}" 
      CommandParameter="{Binding RegViewModel}"> 
     Sign Up 
    </Button> 

我認爲這個代碼CommandParameter="{Binding RegViewModel}"是不正確的按鈕,但我只是不知道如何來取代它......

正因爲如此我得到一個null而不是我的對象在命令功能。 該功能本身沒問題;我已經測試了很多,我試圖通過另一個對象(例如TextBox),它工作正常。

我只是不明白的語法。

是否有可能傳遞在資源中創建的類?

我將非常感謝您的幫助。

回答

3

您試圖使用的方式會暗示它可以在當前的DataContext上找到RegViewModel

指向您的視圖模型本身,你可以說,你綁定的來源是你的RegViewmodel有以下改動。在這種情況下,全部RegViewModel將傳遞到CommandParameter

CommandParameter="{Binding Source={StaticResource RegViewModel}}" 
相關問題