2011-04-07 26 views
0

我似乎無法讓此工作正常。基本上,我有一個綁定到列表的ObservableCollection。在這個集合中,我有一個對象,當它被執行時,我需要使用它作爲變量傳遞給Command。我的計劃是將此作爲CommandParameter傳遞,但我無法使其工作。該對象實際上是一個枚舉值,但我不能讓它與除靜態文本以外的任何東西一起工作。下面是代碼,它使用了一個使用Interactivity(wi)和blend的dll(sl)的MVVM概念。該屬性在ListItem上是公共的,並且實現INotifyPropertyChanged。在Silverlight中發佈綁定命令參數

謝謝。

<ListBox ItemsSource="{Binding Path=MyList}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
        <wi:Interaction.Triggers> 
         <wi:EventTrigger EventName="SelectionChanged"> 
          <sl:InvokeDataCommand CommandParameter="{Binding MyList.ListItem.Property}" Command="{Binding Source={StaticResource Locator}, Path=MyTestPage.TestExecute}" /> 
         </wi:EventTrigger> 
        </wi:Interaction.Triggers> 

... 

回答

0
 <ListBox x:Name="listBox" ItemsSource="{Binding Path=MyList}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
    <wi:Interaction.Triggers>       
    <wi:EventTrigger EventName="SelectionChanged"> 
    <sl:InvokeDataCommand CommandParameter="{Binding ElementName=listBox, Path=SelectedItem.Property}" Command="{Binding Source={StaticResource Locator}, Path=MyTestPage.TestExecute}" /> 
</wi:EventTrigger> 
</wi:Interaction.Triggers> 

如何這樣做呢?你想綁定到selectedItem,不是嗎?

MyList是你的ObservableCollection?