WPF数据绑定 - 显示系统字体列表 [英] WPF Data Binding - Displaying the list of system fonts
本文介绍了WPF数据绑定 - 显示系统字体列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用XAML,我试图获得一个列表框来显示系统字体列表。
Using XAML, I am trying to get a list box to display the list of system fonts.
我不知道在绑定字符串中输入什么。
I am not sure exactly what to type in the Bindings string.
这是我的尝试:
<Window x:Class="ListDataBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:System.Windows.Media;assembly=PresentationCore"
Title="Window1" Height="300" Width="300">
<Grid>
<ListBox ItemsSource="{Binding Source={StaticResource m:Fonts.SystemFontFamilies}}"></ListBox>
</Grid>
</Window>
我收到错误:找不到名为{m:Fonts.SystemFontFamilies}的资源
I get an error: Cannot find resource named '{m:Fonts.SystemFontFamilies}'
我想知道我应该输入什么我没有找到一个有用的MSDN页面 - 如果有人可以指向一个链接,我将不胜感激。
I'm wondering what I should be typing. I haven't managed to find a helpful MSDN page on this - if somebody could point me to a link I'd be grateful.
推荐答案
<Window x:Class="ListDataBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:System.Windows.Media;assembly=PresentationCore"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ObjectDataProvider x:Key="fontFamiliesKey" ObjectType="{x:Type m:Fonts}" MethodName="get_SystemFontFamilies"/>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Source={StaticResource fontFamiliesKey}}"></ListBox>
</Grid>
</Window>
尝试这个
这篇关于WPF数据绑定 - 显示系统字体列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文