I want to modify the font color of the header of a panorama control:
<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>
And my event handler:
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;
});
}
This works perfectly fine until I navigate to another page and navigate back. I used the debugger to see that TitleColor.Color is still being changed everytime I swipe the screen, but the UI is not updated somehow.
Any help is appreciated. Thanks!
-Dan
Try with this code it could help you:
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;
});
}
I think your code works (remarks below) but with the line:
TitleColor.Color = (selectedItem.Foreground as SolidColorBrush).Color;
you are changing the TitleColor
to the same as it is - selectedItem.Foreground as SolidColorBrush
is nothong more than <SolidColorBrush x:Name="TitleColor"...
.
To check it just repleace your code to:
TitleColor.Color = Colors.Brown;
and see what happens.
Remarks:
private async void MainPagePanorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PanoramaItem selectedItem = MainPagePanorama.SelectedItem as PanoramaItem;
await Task.Delay(500);
TitleColor.Color = Colors.Brown;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.