【发布时间】:2013-01-02 21:23:17
【问题描述】:
我正在构建一个地铁风格的应用程序。我设计了一个“设置”弹出窗口,用户可以在其中更改应用的 HomePageView 页面中包含的文本块的字体。
字体是通过一个列出所有系统字体的组合框来选择的。一旦选择了字体(在设置弹出的组合框中),必须更新 HomePageView 页面中的所有文本块。
这是要更新的样式(位于standardstyles.xaml):
<Style x:Key="timeStyle" TargetType="TextBlock">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="333.333"/>
<Setter Property="FontFamily" Value="Segoe UI"/>
</Style>
这是我用来更新文本块样式和访问 SetTextBlockFont 属性以更新文本块外观的代码:
private void fontBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var res = new ResourceDictionary()
{
Source = new Uri("ms-appx:///Common/StandardStyles.xaml", UriKind.Absolute)
};
var style = res["timeStyle"] as Style;
style.Setters.RemoveAt(2);
style.Setters.Add(new Setter(FontFamilyProperty, new FontFamily("Arial")));
HomePageView homePageViewReference = new HomePageView();
homePageViewReference.SetTextBlockFont = style;
}
这是 HomePageView.xaml.cs 中用于更新文本块 (timeHour) 的 SetTextBlockFont 属性:
public Style SetTextBlockFont
{
set
{
timeHour.Style = value;
}
}
应用程序编译时没有错误,但是当我单击组合框中的字体时,没有任何反应。我想是因为我必须加载 HomePageView 页面 homePageViewReference 的新实例,或者因为我必须重新加载页面或类似的东西。
我指出我不能使用 Frame 对象或 NavigationService 类,因为这是一个地铁应用程序。
【问题讨论】:
标签: c# windows-8 microsoft-metro