2013-08-23 60 views
1

我正在使用MVO模式的ComponentOne WPF控件。與MVVM的交互wpf

我在我的視圖模型如下:

public ICommand ClientsEnter 
{ 
    get 
    { 
     if (this.m_ClientsEnter == null) 
     { 
      this.m_ClientsEnter = new DelegateCommand<string>(ClientsLostFocusExecute, 
ClientsLostFocusCanExecute); 
     } 
     return m_ClientsEnter; 
    } 
} 

而且可觀察集合:

public ObservableCollection<Client> Clients 
{ 
    get { return m_Clients; } 
    set 
    { 
     m_Clients = value; 
     RaisePropertyChanged("Clients"); 
    } 
} 

在XAML我添加了一個ComponentOne的組合框,我可以進入客戶端名或ID,然後按回車發射事件來執行ClientsEnter命令:

<Custom1:C1ComboBox Grid.Row="2" Grid.Column="1" Height="24" Name="cmbClients" 
    HorizontalAlignment="Left" VerticalAlignment="Center" ItemsSource="{Binding 
    Clients, Mode=OneWay}" SelectedValuePath="ClientID" DisplayMemberPath="NameE" 
    IsEditable="True" Text="Enter Client Name Or ID" SelectedValue="{Binding 
    Path=Filter.ClientID, Mode=TwoWay}" MinWidth="150" Margin="0,2" Width="189"> 
    <i:Interaction.Triggers> 
     <ei:KeyTrigger Key="enter" FiredOn="KeyUp" ActiveOnFocus="True" SourceName= 
      "cmbClients"> 
      <i:InvokeCommandAction Command="{Binding ClientsEnter, Mode=OneWay}" 
       CommandParameter="{Binding Text,ElementName=cmbClients}" 
       CommandName="KeyDown"/> 
     </ei:KeyTrigger> 
    </i:Interaction.Triggers> 
</Custom1:C1ComboBox> 

我需要知道它爲什麼會這樣做沒有工作,按下後輸入clientID消失,沒有任何反應。即使是文字=「輸入客戶名稱或ID」也沒有出現!有任何想法嗎? 注意,當我改變的關鍵在於空間它的工作原理,但它不採取從組合框的文本,

+0

是你的命令被稱爲然後用戶按下回車鍵?你還可以爲你的命令和Combobox的DataContext(你的視圖模型)提供代碼 – Nikolay

+0

花了2天的時間調查這個問題後,我發現在C1Combobox中存在一個bug,因爲我用telerik Comboxbox取代了它,並且添加了同樣的觸發器而沒有改變任何東西在XAML除了控制,它工作正常。 終於,我不推薦C1 wpf控件 –

回答

1

,我發現有在C1Combobox一個錯誤,因爲我與Telerik的Comboxbox,取而代之的IT支出2天調查這個問題後,添加相同的觸發器,而不更改xaml中除控件外的任何內容,並且工作正常。

最後,我不建議C1 WPF控件