[英]Adding a C# enum value to a Navigation URI
I'm developing a Windows Phone application. 我正在开发Windows Phone应用程序。 I make the question here because I think a silverlight question. 我在这里提出这个问题,是因为我认为这是一个白痴问题。
I have defined the following Navigations URIs on App.xaml: 我在App.xaml上定义了以下导航URI:
<!-- Navigation links-->
<nav:UriMapper x:Name="UriMapper">
<nav:UriMapper.UriMappings>
<nav:UriMapping Uri="/Destination" MappedUri="/Views/Tourism/Common.xaml?Type=1"/>
<nav:UriMapping Uri="/Points" MappedUri="/Views/Tourism/Common.xaml?Type=2"/>
</nav:UriMapper.UriMappings>
</nav:UriMapper>
And the following C# enum: 以及以下C#枚举:
public enum TourismItemType
{
Destination = 1,
PointOfInterest = 2,
Content = 3
}
I want to change the ' 1 ' on MappedUri="/Views/Tourism/Common.xaml?Type= 1 " with the value obtained from TourismItemType.Destination . 我想使用从TourismItemType.Destination获得的值来更改MappedUri =“ / Views / Tourism / Common.xaml?Type = 1 ”上的' 1 '。
I think, I can do that: 我认为,我可以做到:
And do it programatically, but is there any way to access the value represented by TourismType.Destination on XAML? 并且以编程方式进行,但是有什么方法可以访问XAML上的TourismType.Destination表示的值?
Thanks. 谢谢。
This can be easily achieved by passing the value of the enum as a string and then parsing it into an enum in the OnNavigatedTo event. 可以通过将枚举的值作为字符串传递,然后在OnNavigatedTo事件中将其解析为枚举来轻松实现。
MappedUri="/Views/Tourism/Common.xaml?Type=PointOfInterest"
and then in common.xaml: 然后在common.xaml中:
string selectedType = "";
if (NavigationContext.QueryString.TryGetValue("Type", out selectedType))
{
var tit = Enum.Parse(typeof (TourismItemType), selectedType, true);
// do something with `tit`...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.