代码更改和源代码背景. [英] Code changing and themeresource background.
问题描述
你好
我将meresources作为主题资源在我的应用程序中.我有几个themeresourcesX.xaml(x = 1,2,3,4etc)每个都包含其他样式.
我应该如何编程按钮,才能在App中更改代码. xaml.vb:
I use themeresources as a resources of my themes in my application. I have several themeresourcesX.xaml (x=1,2,3,4etc) Each contains other styles.
How should I program button, to change code in App.xaml.vb:
Dim source As String = [String].Format("/Exercises;component/CustomTheme/ThemeResources.xaml")
至
Dim source As String = [String].Format("/Exercises;component/CustomTheme/ThemeResources2.xaml")
按钮将放置在Settings.xaml页中.
是否可以在一页中使用代码来更改代码第二页?
Button will be placed in Settings.xaml page.
Is that possible to use code in one page that changes code of the second page?
还有一个问题.
我想将图像设置为themeresouce.xaml ex的背景. Themeresource1.xaml使用image1.jpg作为背景. Themeresource2.xaml使用image2.jpg作为背景.我知道我可以更改颜色,但是我不确定这些图像.
I would like to set a image as a background of themeresouce.xaml ex. Themeresource1.xaml uses image1.jpg as a background. Themeresource2.xaml uses image2.jpg as a background. I know I can change colors, but I'm not sure about the images.
这是更改颜色背景的方法:
It is the way to change background for color:
<Color x:Key="PhoneBackgroundColor">#FFD81F1F</Color>
但我不想设置颜色,而是设置图像.
推荐答案
关于更改图像,可以使用几种方法:
Regarding changing the image, several approaches can be used:
1.单独的样式(尽管这可能会产生一些代码膨胀,使维护更加困难)
2.将两种资源都具有一种风格,可见性与主题的可见性相关( http://msdn.microsoft.com/zh-cn/library/ff769552(v = vs.92).aspx#BKMK_ThemeVisibilityAndOpacity )
3.对于通用控件("ImageButton"),请将转换器用于ImageSource
1. Separate styles (though this may produce some code bloat making maintenance more difficult)
2. Have both resources in one style, with visibility bound to theme's visibility (http://msdn.microsoft.com/en-us/library/ff769552(v=vs.92).aspx#BKMK_ThemeVisibilityAndOpacity)
3. For generic controls ("ImageButton") use a converter for the ImageSource
(3)的一种变体是将图像URI放入资源字典中,并在启动时根据主题在运行时对其进行更新.像这样:
A variation on (3) is to put the image URI into a resource dictionary and update that at runtime based on the theme at startup. Like this:
<Style>
...
<Image Source="{StaticResource MyImageUri}"
...
</Style>
this.Resources.Remove("MyImageUri");
if ( (Visibility)this.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible)
{
this.Resources.Add("MyImageUri", "/Images/dark.png");
}
else
{
this.Resources.Add("MyImageUri", "/Images/light.png");
}
More resources regarding general theme management can be found here.
希望这会有所帮助,
标记
Hope this helps,
Mark
这篇关于代码更改和源代码背景.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!