【发布时间】:2015-05-10 08:43:23
【问题描述】:
我正在创建一个 Windows Phone 8.1 应用程序,在该应用程序中,我使用了许多应根据所选主题浅色或深色显示的图像。
使用正确的命名和缩放比例创建明暗图像。
我创建了以下 ThemeResource 来根据所选主题设置图像源。
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<Style x:Key="ShowImage" TargetType="Image">
<Setter Property="Source" Value="Assets/image.png"/>
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<Style x:Key="ShowImage" TargetType="Image">
<Setter Property="Source" value="Assets/image.png"/>
</Style>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
以及必要时显示图像的 XAML。
<Grid>
<Image HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="None"
Style="{ThemeResource ShowImage}">
</Image>
</Grid>
当我使用选择的主题启动应用程序时,每次都会显示正确的图像。但是,当我选择不同的主题然后切换回我的应用程序时,我可以看到背景颜色已更新,但我的图像并未动态更新。
据我所知,应该使用 ThemeResource 来动态更新它,但我无法让它工作。 有人知道我的 XAML 代码有什么问题吗?
【问题讨论】:
标签: c# xaml windows-phone-8.1 winrt-xaml