0

Silverlight mvvm にコンボボックスがあります。コンボボックス名「SelectionChanged」のイベントを作成する必要があります。i 以下のコーディングを作成しますが、エラーが発生します。

注: 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}" />
4

2 に答える 2

1

私のために働いているようです。次のことを確認してください。

  1. ここから SL5 の Blend Preview をインストールします
  2. 参照System.Windows.InteractivityMicrosoft.Expression.Interactionsて、Silverlight プロジェクトで
  3. XAML で正しい名前空間を定義します。xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
于 2012-10-17T20:52:36.050 に答える
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>

ここで Employees は、監視可能なコレクション内のすべての従業員を取得するためのデータソースのようなものです。そのコードは Employee.cs ファイルに記述されます。

次に、次のように ComboboxSelected イベントにアクセスします。ViewModel フォルダーに移動し、次のように名前が付けられた関数を作成します。

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

ハッピーコーディング...!

于 2012-10-18T04:48:36.673 に答える