2012-03-04 87 views
1

我需要在WP7上显示已安装的字体。有没有简单的方法来做到这一点? 截至目前我正试图绑定使用ListPicker的字体名称和列表,但实际上我并不需要。在WP7中显示字体

我需要找到WP7上列出的字体,并在ListPicker全屏模式下显示它们。

这是我现在有:

数据模板

<DataTemplate x:Name="lpkFontNames"> 
     <TextBlock Text="{Binding FontNames}" /> 
</DataTemplate> 

* ListPicker:*

<toolkit:ListPicker FullModeItemTemplate="{Binding lpkFontNames}" 
       Grid.Row="1" Grid.Column="1" x:Name="lpkFontName" Width="290" Height="63" FullModeHeader="Selct Font Name"/> 

而在代码隐藏:

Dim FontNames() As String = { "Arial","Segoe UI", "Times New Roman", "Cambria"} 

Me.lpkFontName.ItemsSource = FontNames 

* 编辑:*

我跟着this但我无法填充他们

回答

1

问题是与你的DataTemplate - 你TextBlock的结合不会有‘FontNames’属性。对于ListPickerItemsSource中的每个项目,您的DataTemplate的实例将被创建并绑定到ItemsSource中的该项目。你想要做的就是将TextBlock的属性直接绑定到已创建DataTemplate的项目。例如;

<DataTemplate x:Name="lpkFontNames"> 
    <TextBlock Text="{Binding}" 
       FontFamily="{Binding}" 
       /> 
</DataTemplate> 

我假定你想要的字体名称,字体本身显示,按Custom Font Picker?如果不是,请将您的DataTemplate中的TextBlockFontFamily属性删除。例如;

<DataTemplate x:Name="lpkFontNames"> 
    <TextBlock Text="{Binding}" 
       /> 
</DataTemplate> 
+0

@ MrMDavidson,感谢您的回复,我得到了它的工作,如果我需要获得所选字体做什么我需要做这样我需要得到与此类似:?textbox1.text = ListPicker。 SelectedFont.Can我做了这样的事情来获得选定的字体。 – coder 2012-03-07 08:00:45

+0

您可以通过使用SelectedItem属性来获取ListPicker的当前选定项目。由于这是一个对象,你需要将它转换为适当的类型(在你的情况下为'string')。如果你启用了多个选择,你可以通过'SelectedItems'(注意** s **)属性来获得'IList'。同样,需要适当地投射每个项目。 – MrMDavidson 2012-03-07 23:16:32