Windows phone 7 针对ListBox设置触发器时引发异常
我正在重新访问一个我参与过的MVVM Windows Phone项目,在向列表框添加触发器时遇到了一个问题。我已将我的项目升级到7.1。我以前的代码如下:-Windows phone 7 针对ListBox设置触发器时引发异常,windows-phone-7,windows-phone-7.1,Windows Phone 7,Windows Phone 7.1,我正在重新访问一个我参与过的MVVM Windows Phone项目,在向列表框添加触发器时遇到了一个问题。我已将我的项目升级到7.1。我以前的代码如下:- <ListBox x:Name="MainListBox" ItemsSource="{Binding MyItems}" Grid.Row="1" Margin="12" I
<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}" />
但是,我现在收到如下例外情况:-
<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>
我已经搜索了异常消息,但是我不确定为什么“内联”触发器设置会起作用而不再起作用
有人能解释一下吗?我想说的是,当你内联操作时,你可以设置值。您正在设置一个集合
通常建议将集合设置为只读,它们可能会更改该位,通过另一种方式,您可以将添加到集合中,即使集合是只读的,这也没有问题