答:可以在Visual Studio中使用设计器来查看页面在不同主题/口音组合下的外观。使用设备窗口(在“设计”菜单下)。 Blend中也存在类似的选项。
B)你可以做到这一点与转换器,但我喜欢做我自己的资源,这样的事情。只要创建一个这样的类:
public class MyColorResource
{
/// <summary>
/// The resource name - as it can be referenced by within the app
/// </summary>
private const string ResourceName = "MyColorResource";
/// <summary>
/// Initializes a new instance of the <see cref="MyColorResource"/> class.
/// </summary>
public MyColorResource()
{
try
{
// This doesn't work in the designer - so don't even try
if (DesignerProperties.IsInDesignTool)
{
return;
}
// Make sure we don't try and add the resource more than once - would happen if referenced on multiple pages or in app and page(s)
if (!Application.Current.Resources.Contains(ResourceName))
{
if (Visibility.Visible == (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"])
{
Application.Current.Resources.Add(ResourceName, new SolidColorBrush(Colors.Red));
}
else
{
Application.Current.Resources.Add(ResourceName, new SolidColorBrush(Colors.Gray));
}
}
}
catch (Exception exc)
{
System.Diagnostics.Debug.WriteLine("Something went wrong - ask for your money back");
System.Diagnostics.Debug.WriteLine(exc);
}
}
}
某处在您的应用程序做一个参考,以它(在App.xaml中或您的主网页通常是好)
<phone:PhoneApplicationPage.Resources>
<local:MyColorResource x:Key="AnythingAsNotActuallyUsed" />
</phone:PhoneApplicationPage.Resources>
然后,您可以使用它像任何其他资源一样的XAML:
<TextBlock Foreground="{StaticResource MyColorResource}" Text="{Binding Name}" />