簡體   English   中英

將C#枚舉值添加到導航URI

[英]Adding a C# enum value to a Navigation URI

我正在開發Windows Phone應用程序。 我在這里提出這個問題,是因為我認為這是一個白痴問題。

我在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>

以及以下C#枚舉:

public enum TourismItemType
{
    Destination = 1,
    PointOfInterest = 2,
    Content = 3
}

我想使用從TourismItemType.Destination獲得的值來更改MappedUri =“ / Views / Tourism / Common.xaml?Type = 1 ”上的' 1 '。

我認為,我可以做到:

並且以編程方式進行,但是有什么方法可以訪問XAML上的TourismType.Destination表示的值?

謝謝。

可以通過將枚舉的值作為字符串傳遞,然后在OnNavigatedTo事件中將其解析為枚舉來輕松實現。

MappedUri="/Views/Tourism/Common.xaml?Type=PointOfInterest"

然后在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM