gpt4 book ai didi

wpf - WPF Modern UI 的 '#1' 中的 '/Content/LoremIpsum.xaml#1' 是什么意思?

转载 作者:行者123 更新时间:2023-12-04 16:05:22 27 4
gpt4 key购买 nike

我正在调查 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 中使用选定的源绑定(bind)时,您可以简单地解析出 # 之后的所有内容找到您的index选择的选项卡。您必须收听 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 一起使用导航。这个问题的界面:

Caliburn.Micro + MEF + Modern UI: IContent events

关于wpf - WPF Modern UI 的 '#1' 中的 '/Content/LoremIpsum.xaml#1' 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22137628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com