【发布时间】:2016-12-19 04:52:15
【问题描述】:
我使用了几个标签,当用户点击其中一个标签时,它会打开一个新页面。但问题是,只要有人点击其中一个标签,就会打开多个页面。
下面我会附上xaml和代码。
Xaml
<StackLayout x:Name="dropdownStack" Padding="10" VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Vertical" BackgroundColor="#033c73" IsVisible="False">
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Home"/>
<Label x:Name="ddmenu_Home" HorizontalOptions="FillAndExpand" Text="Home" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Social"/>
<Label x:Name="ddmenu_Social" HorizontalOptions="FillAndExpand" Text="Social" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Careers"/>
<Label x:Name="ddmenu_Careers" HorizontalOptions="FillAndExpand" Text="Careers" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Schedule"/>
<Label x:Name="ddmenu_MySchedule" HorizontalOptions="FillAndExpand" Text="My Schedule" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Contact"/>
<Label x:Name="ddmenu_Contact" HorizontalOptions="FillAndExpand" Text="Contact" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ddm_Details"/>
<Label x:Name="ddmenu_MyDetails" HorizontalOptions="FillAndExpand" Text="My Details" TextColor="#ffffff"/>
</StackLayout>
<StackLayout VerticalOptions="Fill" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Image Source="ic_video"/>
<Label x:Name="ddmenu_Videos" HorizontalOptions="FillAndExpand" Text="Videos" TextColor="#ffffff"/>
</StackLayout>
</StackLayout>
C#
public void OnDropdownItemPressed()
{
dropdownStack.IsVisible = !dropdownStack.IsVisible;
ddmenu_Home.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
Navigation.PushAsync(new MainPage());
})
});
ddmenu_Social.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
Navigation.PushAsync(new SocialPage());
})
});
ddmenu_Careers.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
Navigation.PushAsync(new CareersPage());
})
});
ddmenu_MySchedule.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
RegisterDeviceWithWebview(ProjectVariables.URL + ProjectVariables.URL_EXT_SCHEDULE, ProjectVariables.regID);
})
});
ddmenu_Contact.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
RegisterDeviceWithWebview(ProjectVariables.URL + ProjectVariables.URL_EXT_CONTACT, ProjectVariables.regID);
})
});
ddmenu_MyDetails.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
RegisterDeviceWithWebview(ProjectVariables.URL + ProjectVariables.URL_EXT_DETAILS, ProjectVariables.regID);
})
});
ddmenu_Videos.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() =>
{
RegisterDeviceWithWebview(ProjectVariables.URL + ProjectVariables.URL_EXT_VIDEOS, ProjectVariables.regID);
})
});
}
如果有人可以提供帮助,那就太好了。
【问题讨论】:
-
我的建议怎么样?
标签: c# .net wpf xaml xamarin.forms