WPF:数据绑定和显示成员路径

发布于 2024-09-17 16:43:33 字数 792 浏览 3 评论 0原文

我创建了一个 RibbonGallery/ComboBox 来显示已安装字体的列表。

alt text

但有时输入后说“V”,这就是我得到的

alt text

查看菜单中的文本。

[Font Family: Name=...

为什么会发生这种情况。

代码

// xaml
<ribbon:RibbonComboBox Label="Gallery">
    <ribbon:RibbonGallery SelectedValue="ABC" SelectedValuePath="Content" MaxColumnCount="1">
        <ribbon:RibbonGalleryCategory x:Name="fontsMenu" />
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

// code behind
InstalledFontCollection col = new InstalledFontCollection();
fontsMenu.ItemsSource = col.Families;
fontsMenu.DisplayMemberPath = "Name";

i have created a RibbonGallery/ComboBox to display a list of installed fonts.

alt text

but sometimes after entering say "V" this is what i get

alt text

look at the text in the menu.

[Font Family: Name=...

why is that happening.

code

// xaml
<ribbon:RibbonComboBox Label="Gallery">
    <ribbon:RibbonGallery SelectedValue="ABC" SelectedValuePath="Content" MaxColumnCount="1">
        <ribbon:RibbonGalleryCategory x:Name="fontsMenu" />
    </ribbon:RibbonGallery>
</ribbon:RibbonComboBox>

// code behind
InstalledFontCollection col = new InstalledFontCollection();
fontsMenu.ItemsSource = col.Families;
fontsMenu.DisplayMemberPath = "Name";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2024-09-24 16:43:33

这就是 FontFamily.ToString() 的实现方式,这正是我们所显示的:

  public override string ToString()
   {
      return string.Format(CultureInfo.CurrentCulture, "[{0}: Name={1}]", new object[] {  base.GetType().Name, this.Name });
    }

您肯定需要将一些 DisplayMemberPath 设置为“Name”,并且您已经在 RibbonGalleryCategory 上设置了一个,但现在我很好奇 - 不应该在 RibbonGallery 甚至 RibbonComboBox 上设置它?坦率地说,我还没有使用过 wpf 功能区控件 - 我所能建议的只是假设。

希望这会有所帮助:)

That's how FontFamily.ToString() implemented and thats exactly what we have displayed:

  public override string ToString()
   {
      return string.Format(CultureInfo.CurrentCulture, "[{0}: Name={1}]", new object[] {  base.GetType().Name, this.Name });
    }

You definitely need to set some DisplayMemberPath to "Name" and you already have one on RibbonGalleryCategory but now i'm curious - shouldnt it be set on RibbonGallery or even RibbonComboBox? Frankly speaking i haven't used wpf ribbon controls yet - all i can suggest is just assumption.

Hope this'll help :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文