2012-03-23 44 views
1

我正在重溫一個我曾經工作過的MVVM Windows Phone項目,當我將一個Trigger添加到ListBox時遇到問題。我已將項目升級到7.1。我以前有代碼如下: -設置針對ListBox的觸發器時引發的異常

  <ListBox x:Name="MainListBox" 
       ItemsSource="{Binding MyItems}" 
       Grid.Row="1" 
       Margin="12" 
       ItemContainerStyle="{StaticResource MyListItemStyle1}" 
       SelectedIndex="{Binding CurrentSelectedIndex, Mode=TwoWay}" 
       ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
       i:Interaction.Triggers="{StaticResource PerformSelectionChangedEventTrigger}" /> 

不過我現在收到的異常,如下所示: -

無法設置只讀屬性「System.Windows.Interactivity.Interaction.Triggers

進行以下更改似乎解決這個問題: - 我已經尋找異常消息

  <ListBox x:Name="MainListBox" 
       ItemsSource="{Binding MyListItems}" 
       Grid.Row="1" 
       Margin="12" 
       ItemContainerStyle="{StaticResource MyListItemStyle1}" 
       SelectedIndex="{Binding CurrentSelectedIndex, Mode=TwoWay}" 
       ScrollViewer.HorizontalScrollBarVisibility="Disabled">     
      <i:Interaction.Triggers> 
       <i:EventTrigger EventName="SelectionChanged"> 
        <cmdextras:EventToCommand Command="{Binding Path=PerformSelectionChanged}" 
               PassEventArgsToCommand="True" /> 
       </i:EventTrigger> 
      </i:Interaction.Triggers> 
     </ListBox> 

但是我不確定爲什麼「內聯」觸發設置使用爲w ork不再有效。

有人能夠對此有所瞭解嗎?

回答

2

我會說,當你這樣做內嵌設置的值。你正在設置一個集合。

通常建議將集合只讀,他們可能會改變這一點,並以另一種方式做,添加到集合中,即使集合是隻讀集合也沒有問題。