[英]What does the '#1' mean in '/Content/LoremIpsum.xaml#1' of Modern UI for WPF?
這些天,我正在研究ModernUI
,修改代碼時遇到了一些問題。 問題來自TabControl
。 來自MUI DOC
的示例如下:
<Grid Style="{StaticResource ContentRoot}">
<mui:ModernTab SelectedSource="/Content/LoremIpsum.xaml#1" Layout="List">
<mui:ModernTab.Links>
<mui:Link DisplayName="Lorem Ipsum 1" Source="/Content/LoremIpsum.xaml#1" />
<mui:Link DisplayName="Lorem Ipsum 2" Source="/Content/LoremIpsum.xaml#2" />
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
誰能告訴我上面代碼中#1
的用法?
在這種情況下,將使用片段導航。 這意味着,當您在ViewModel
使用選定的源綁定時,您只需簡單地解析#
之后的所有內容,即可找到所選標簽的index
。 您必須偵聽SourceChanged
類型的SourceChanged
,才能知道用戶選擇了哪個選項卡,或者使用OnFragmentNavigation
事件。
為此,使用以下代碼:
namespace FirstFloor.ModernUI.Windows.Navigation
FragmentNavigationEventArgs.cs
/// <summary>
/// Provides data for fragment navigation events.
/// </summary>
public class FragmentNavigationEventArgs
: EventArgs
{
/// <summary>
/// Gets the uniform resource identifier (URI) fragment.
/// </summary>
public string Fragment { get; internal set; }
}
namespace FirstFloor.ModernUI.Windows
IContent.cs
/// <summary>
/// Defines the optional contract for content loaded in a ModernFrame.
/// </summary>
public interface IContent
{
/// <summary>
/// Called when navigation to a content fragment begins.
/// </summary>
/// <param name="e">An object that contains the navigation data.</param>
void OnFragmentNavigation(FragmentNavigationEventArgs e);
...
}
namespace FirstFloor.ModernUI.Windows.Navigation
NavigationHelper.cs
/// <summary>
/// Removes the fragment from specified uri and return it.
/// </summary>
/// <param name="uri">The uri</param>
/// <returns>The uri without the fragment, or the uri itself if no fragment is found</returns>
public static Uri RemoveFragment(Uri uri)
{
string fragment;
return RemoveFragment(uri, out fragment);
}
/// <summary>
/// Removes the fragment from specified uri and returns the uri without the fragment and the fragment itself.
/// </summary>
/// <param name="uri">The uri.</param>
/// <param name="fragment">The fragment, null if no fragment found</param>
/// <returns>The uri without the fragment, or the uri itself if no fragment is found</returns>
public static Uri RemoveFragment(Uri uri, out string fragment)
{
fragment = null;
if (uri != null) {
var value = uri.OriginalString;
var i = value.IndexOf('#');
if (i != -1) {
fragment = value.Substring(i + 1);
uri = new Uri(value.Substring(0, i), uri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative);
}
}
return uri;
}
您也可以在此問題中看到一個與IContent
接口一起用於導航的示例:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.