识别用户发起的事件

时间:2018-04-18 06:54:20

标签: c# xamarin xamarin.forms

我正在开发Xamarin Forms项目和Visual Studio 2017.我在列表视图中切换按钮我需要删除切换事件并使用代码再次添加它。我无法获得切换名称,因为它位于列表视图中。有什么方法可以从代码或用户操作中识别事件触发器吗? XAML低于

<ListView x:Name="listData"  
            Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="7"
            SeparatorColor="Transparent" BackgroundColor="Transparent" 
            HasUnevenRows="True" IsVisible="false">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Vertical">
                    <StackLayout Orientation="Vertical">
                        <Switch 
                            Scale="0.85"
                            WidthRequest="50"
                            HeightRequest="35"
                            IsToggled="{Binding IsCrewMemberSelected}"
                            VerticalOptions="Center"
                            HorizontalOptions="Start"
                            Toggled="Handle_IndividualToggled"
                            Margin="0,0,0,0"/>
                        <Label 
                            HeightRequest="35"
                            TextColor="#FFFFFF"
                            FontFamily="Open Sans"
                            FontSize="16"          
                            Text="{Binding CrewMemberName}"
                            VerticalOptions="Center"
                            HorizontalOptions="Start"
                            Margin="60,-35,0,0"/>
                    </StackLayout>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

1 个答案:

答案 0 :(得分:0)

只需绑定listView中的开关

即可
<Switch IsToggled="{Binding isToggled, Mode=TwoWay}" ></Switch>

并在该列表的Object中将变量定义为:

public Problem(string ProblemID, string ProblemName,bool isToggled)
{
    this.ProblemID = ProblemID;
    this.ProblemName = ProblemName;
    this.isToggled = isToggled;
}

由于您绑定了该值,因此可以在将项目添加到true时初始化交换机,并且它将启用此项。默认为false,这将使关闭。

之后,使用一个简单的循环来获取isToggled == true的所有项目。

相关问题