2015-02-07 34 views
1

如果我把下面的代碼在骨架WinRT的應用程序,也不會構建主頁:的WinRT ListPickerFlyout應用程序崩潰,如果背景顏色改變

<Page 
x:Class="TestApp1.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:TestApp1" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
Background="Blue"> 

<Page.Resources> 
    <ListPickerFlyout x:Key="btnfly"/> 
</Page.Resources> 

<Grid> 

</Grid> 
</Page> 

的錯誤是:

An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in TestApp1.WindowsPhone.exe but was not handled in user code WinRT information: Cannot create instance of type '%0' [Line: 12 Position: 42]

更改背景標記回{ThemeResource ApplicationPageBackgroundThemeBrush}解決了問題。

任何想法如何改變我的網頁的背景顏色,仍然使用ListPickerFlyout?

回答

0

簡單的解決方法是後調用設置在構造函數中的背景顏色,InitializeComponent

public MainPage() 
{ 
    this.InitializeComponent(); 

    // Or the colour of your choice... 
    Background = new SolidColorBrush(Windows.UI.Colors.Blue); 

    this.NavigationCacheMode = NavigationCacheMode.Required; 
} 

一個有趣的問題是「爲什麼?」 - 我的猜測是,因爲ListPickerFlyout實際上並不是UIElement,所以在初始化過程中會出現一些奇怪的交互。

0

是的,「爲什麼」是一個有趣的問題,彼得的答案是好的。

我還發現另一個StackOverflow問題的答案。

​​

然後改變頁面的背景Background="{ThemeResource FlyoutBackgroundThemeBrush}"

首先,通過加入以下的App.xaml覆蓋FlyoutBackgroundThemeBrush