【发布时间】:2021-04-16 16:25:54
【问题描述】:
我在集合视图中使用 Xamarin 表单切换,如下所示。
<CollectionView ItemsSource="{Binding SwitchStatus}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<StackLayout HeightRequest="100" Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Spacing="30">
<Switch x:Name="mySwitch" IsToggled="{Binding State}">
<Switch.Behaviors>
<prism:EventToCommandBehavior EventName="Toggled" CommandParameter="{Binding .}" Command="{Binding BindingContext.UpdateCommand,Source={x:Reference myPage}}"/>
</Switch.Behaviors>
</Switch>
</StackLayout>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
由于设置了 IsToggled Binding 属性,每当我导航到该页面时,都会自动触发 Switch 的 Toggled 事件。当用户未手动触发时,有什么方法可以限制 Switch Toggled 事件?
为了更清楚,我附上了我的sample here。
Followed prism MVVM, EventToCommandBehavior 我应该都跟着这些。
帮我提供示例代码会很棒。
【问题讨论】:
标签: user-interface xamarin xamarin.forms switchcontrol