2017-01-30 27 views
0

我想用一些FontAwesome图标来重新搭配汉堡包菜单,我的做法是在我的应用程序中使用ResourseDictionoary。现在我想把关键字FontAwesomeUserString绑定为字形波纹管。我的对象中的属性是类型为string的图标。在我的列表中,Icon var x:DataType="local:MenuItem"具有我的resoursedictionary中的值。Binding StaticResourse Key in uwp

<FontIcon Grid.Column="0" FontFamily="{StaticResource FontAwesomeFontFamily}" Glyph="{StaticResource FontAwesomeUserString}" Foreground="White" /> 
<TextBlock Grid.Column="1" Text="{x:Bind Name, Mode=OneWay}" TextWrapping="Wrap" FontSize="16" VerticalAlignment="Center" Foreground="White"/> 

请告诉我是否/我该如何绑定StaticResourse的ResourceKey属性。 谢谢

+0

您还需要发布资源代码。你在这里正确地做到了。请记住{StaticResource}与{Binding}不同,但是您所做的事情看起来是正确的。 –

+0

Hi @MichaelPuckettII。感谢你的回答。你可以找到源代码[这里](https://github.com/amoraitis/AuebUnofficial/blob/Dev/AuebUnofficial/Helpers/HandlingUI/FontAwesomeDictionary.xaml),我想要静态资源从代码中获取所有的值[后面](https://github.com/amoraitis/AuebUnofficial/blob/Dev/AuebUnofficial/Navig.xaml.cs),这里是我在[xaml]中的代码(https://github.com/amoraitis/AuebUnofficial/ blob/Dev/AuebUnofficial/Navig.xaml) –

+0

谢谢Anastasios。然而;文森特下面已经回答了这个问题,就像我会给出或者考虑他看到的那样。 –

回答

1

您可以通过替换他们通过类似的代码更改资源字典的值:

Application.Current.Resources["FontAwesomeUserString"] = "&glyphCode"; 

不要忘记,StaticResource创建页面时是只读的。

根据更新字典时的情况,这可能已足够,但如果希望应用程序在更改资源字典中的某些内容时自行更新,则必须使用ThemeResource

你可以得到ThemeResourcehere的更多详细信息。

<FontIcon Grid.Column="0" 
    FontFamily="{ThemeResource FontAwesomeFontFamily}" 
    Glyph="{ThemeResource FontAwesomeUserString}" 
    Foreground="White" /> 

更新

如果你只是想设置字形/字体系列所有作品,经常结合是不够的:

<DataTemplate x:Key="DefaultTemplate" x:DataType="local:MenuItem"> 
     <Grid Width="240" Height="48"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="48" /> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 

      <FontIcon Grid.Column="0" FontFamily="{x:Bind FontFamily}" Glyph="{x:Bind Icon}" Foreground="White" /> 
      <TextBlock Grid.Column="1" Text="{x:Bind Name, Mode=OneWay}" TextWrapping="Wrap" FontSize="16" VerticalAlignment="Center" Foreground="White"/> 
     </Grid> 
    </DataTemplate>   

你只需要定义FontFamilyIcon在你的视图mod中。 el 您可以查看UWP工具包中的汉堡菜单documentation

+0

谢谢你的答案,我看不出我如何在一个对象[这个](http://prnt.sc/e2d5u1)中实现这个绑定。我希望它采取不同的价值观。不仅是'FontAwesomeUserString'值。 –