2012-10-17 44 views
0

我在silverlight mvvm中有一個組合框。我需要爲組合框名稱'SelectionChanged'編寫事件。我在下面創建編碼,但它給出了一個錯誤..「在'InvokeCommandAction'類型中找不到屬性'命令'」在「InvokeCommandAction」類型中找不到屬性「命令」組合框

注意:我沒有使用Silverlight Light。我正在使用Silverlight5及其Silverlight應用程序。

<ComboBox x:Name="myComboBox" Width="150" ItemsSource="{Binding Items}" > 
            <ComboBox.ItemTemplate> 
             <DataTemplate> 
              <StackPanel> 
               <TextBlock Text="{Binding Name}"/> 
              </StackPanel> 
             </DataTemplate> 
            </ComboBox.ItemTemplate> 
            <i:Interaction.Triggers> 
             <i:EventTrigger EventName="SelectionChanged"> 
              <i:InvokeCommandAction Command="{Binding LoadCommand}" CommandParameter="{Binding SelectedItem, ElementName=myComboBox}" /> 
             </i:EventTrigger> 
            </i:Interaction.Triggers> 
           </ComboBox> 

這行錯誤來了。

<i:InvokeCommandAction Command="{Binding LoadCommand}" CommandParameter="{Binding SelectedItem, ElementName=myComboBox}" /> 
+0

您正在使用哪種版本的Silverlight?這是一個Silverlight應用程序或WP7應用程序? –

+0

我正在使用Silverlight 5 ..它的Silverlight應用程序。 –

回答

0

喜終於讓我找到爲它的解決方案.. 我在下面的XAML頁面中包含:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
      xmlns:si="clr-namespace:Expression.Samples.Interactivity;assembly=Expression.Samples.Interactivity" 

然後組合框的代碼是:

<ComboBox ItemsSource="{Binding Employees,Mode=TwoWay}" DisplayMemberPath="Dept" SelectedItem="{Binding Names, Mode=TwoWay}" Margin="130,117,0,0" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120"> 
      <i:Interaction.Triggers> 
       <i:EventTrigger EventName="SelectionChanged"> 
        <si:CallDataMethod Method="AddEmployee"/> 
        <si:SetProperty TargetName="LayoutRoot" PropertyName="Background" Value="PaleGoldenrod"/> 
       </i:EventTrigger> 
      </i:Interaction.Triggers> 
     </ComboBox> 

這裏的員工就像是一個數據源獲取所有員工在觀察集合。 該代碼將寫入Employee.cs文件中。

那麼我們訪問ComboboxSelected事件如下.. 轉到視圖模型文件夾並命名寫如下的功能,

public void AddEmployee() 
{ 
//Your Code.... 
} 

編碼快樂...!

1

似乎是爲我工作。請確保您:

  1. here
  2. 參考System.Windows.InteractivityMicrosoft.Expression.Interactions在你的Silverlight項目安裝混合預覽SL5
  3. 定義正確的命名空間中的XAML:xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
+0

請注意,這個答案適用於我(只是第2步 - 添加引用),即使我不使用SilverLight(WPF 4.5) – Simon

相關問題