[英]Use qualifiers in image file names does not work in UWP runtime
I was trying to change image for Theme/HighContrast change in UWP app.我试图在 UWP 应用程序中更改主题/高对比度更改的图像。 I followed the link: tailor-resources But it is not working when I change theme while app is running.
我点击了链接: 定制资源但是当我在应用程序运行时更改主题时它不起作用。 It works after app restarting.
它在应用程序重新启动后工作。 I followed folder name qualifiers & file name qualifiers both.
我同时遵循了文件夹名称限定符和文件名限定符。 Do I need to do any additional changes?
我需要做任何额外的改变吗? Can anyone please help me?
谁能帮帮我吗?
but it is not working when I change theme while app is running.
但是当我在应用程序运行时更改主题时它不起作用。 It works after app restarting.
它在应用程序重新启动后工作。
It is by design, derive from official document , we need to listen MapChanged event that will be invoked when the system contrast theme changed.它是设计使然,源自官方文档,我们需要监听系统对比度主题更改时将调用的MapChanged事件。 And modify the image source manually.
并手动修改图像源。
For example:例如:
public MainPage()
{
this.InitializeComponent();
var qualifierValues = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
qualifierValues.MapChanged += new Windows.Foundation.Collections.MapChangedEventHandler<string, string>(QualifierValues_MapChanged);
}
private async void QualifierValues_MapChanged(IObservableMap<string, string> sender, IMapChangedEventArgs<string> @event)
{
var dispatcher = this.MyImage.Dispatcher;
if (dispatcher.HasThreadAccess)
{
this.RefreshUIImages();
}
else
{
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => this.RefreshUIImages());
}
}
private void RefreshUIImages()
{
var namedResource = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap[@"Files/Assets/Images/logo.jpg"];
this.MyImage.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(namedResource.Uri);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.