我想修改全景图控件标题的字体颜色:
<phone:Panorama Name="MainPagePanorama"
Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
Background="{StaticResource QuotePaperBackground}"
SelectionChanged="MainPagePanorama_SelectionChanged">
<phone:Panorama.Foreground>
<SolidColorBrush x:Name="TitleColor" Color="{Binding Red, Source={StaticResource WP8AccentColors}}"/>
</phone:Panorama.Foreground>
...
</phone:Panorama>
我的事件处理程序:
private void MainPagePanorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedItem = MainPagePanorama.SelectedItem as PanoramaItem;
Deployment.Current.Dispatcher.BeginInvoke(async () =>
{
await Task.Delay(500);
TitleColor.Color = (selectedItem.Foreground as SolidColorBrush).Color;
});
}
这很好用,直到我导航到另一个页面并导航回来。我使用调试器看到每次刷屏幕时仍然会更改TitleColor.Color,但UI不会以某种方式更新。
感谢任何帮助。谢谢!
-Dan
答案 0 :(得分:0)
尝试使用此代码可以帮助您:
private async void MainPagePanorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedItem = MainPagePanorama.SelectedItem as PanoramaItem;
await Task.Run(() =>
{
Thread.Sleep(100);
TitleColor.Color = (selectedItem.Foreground as SolidColorBrush).Color;
});
}
答案 1 :(得分:0)
我认为您的代码有效(下面的评论),但有一行:
TitleColor.Color = (selectedItem.Foreground as SolidColorBrush).Color;
您要将TitleColor
更改为原样 - selectedItem.Foreground as SolidColorBrush
不超过<SolidColorBrush x:Name="TitleColor"...
。
要检查它,只需将您的代码补充到:
TitleColor.Color = Colors.Brown;
看看会发生什么。
说明:
private async void MainPagePanorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PanoramaItem selectedItem = MainPagePanorama.SelectedItem as PanoramaItem;
await Task.Delay(500);
TitleColor.Color = Colors.Brown;
}