当我在Windows 8商店应用程序上创建新页面时,它具有我想要更改的默认颜色。如果我删除页面上的所有元素并更改背景颜色,它将无效。我在下面的示例中将背景设置为粉红色。如何使这种颜色生效? (我也删除了App.xaml中的所有内容)
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="DemoWindows8StoreApp.BasicPage3"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DemoWindows8StoreApp"
xmlns:common="using:DemoWindows8StoreApp.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="Pink"
mc:Ignorable="d">
答案 0 :(得分:0)
更新1
每个控件可能会根据其视觉效果以不同方式应用此属性 模板。此属性仅影响其模板使用的控件 背景属性作为参数。在其他控件上,此属性 没有效果。有关可视化模板的更多信息,请参阅模板 属性。
因此,Page
的模板可能不会将Background
属性用作参数。
从项目中删除任何内容以更改颜色。转到Common \ StandardStyles.xaml。搜索“LayoutRootStyle”。你会找到Panel
的样式。在那里更改Background
。请注意,这将影响项目中的所有页面。如果您想为不同的页面使用不同的颜色,那么您可以为每个页面创建单独的样式。
<Style x:Key="LayoutRootStyle" TargetType="Panel">
<Setter Property="Background" Value="Pink"/>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
答案 1 :(得分:0)
最好遵循默认模板,而不是设置页面背景,而是设置根元素(通常是网格),我不能100%确定为什么该页面上的背景不起作用(我怀疑控制模板。)