答:可以在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}" />