我目前正在开发一个具有白色文本和透明背景的用户控件.不幸的是因为VS2010中的XAML设计视图有白色背景我看不到任何我正在设计的东西!
我已经浏览了所有我能想到的设置对话框,但一直无法找到改变XAML设计器背景颜色的设置.
有谁知道如何做到这一点?
我有一个白色文本前景色和透明背景色的控件.稍后,此usercontrol将添加到带有真实背景颜色的不同控件中.
然而在设计这个时,在VS 2010中控制白色背景上的白色前景,我显然无法看到任何东西.无论如何,只为设计时间定义不同的颜色?
我试过这个:
if (System.ComponentModel.DesignerProperties.IsInDesignTool)
{
LayoutRoot.Background = new SolidColorBrush(Colors.Blue);
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有小费吗?
更新:
我不明白这对你们有什么用.我创建了一个新的Silverlight 4.0应用程序,并将这行代码插入到ctor中:
public MainPage()
{
InitializeComponent();
LayoutRoot.Background = new SolidColorBrush(Colors.Blue);
}
<UserControl x:Class="SilverlightApplication3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot">
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
当我进入Designer时,我仍然不认为它是蓝色的.我甚至没有任何isInDesignTime条件.我在这里缺少什么?
谢谢,Kave
我正在使用visual studio黑暗主题.因此,在设计我的视图时,如果字体为黑色,则无法看到字体.修复方法是将视图的背景设置为白色.但我们的应用程序有不同的主题,所以我不能硬编码.
我在创建usercontrol时使用了很多属性:
d:DesignWidth="1110" d:DesignHeight="400"
Run Code Online (Sandbox Code Playgroud)
这些属性仅在设计时影响视图.如果我可以创建一个属性d:DesignBackground,这样我就不必每次运行应用程序时都添加和删除background属性.
我尝试了这个现有答案中解释的两种方法,但它们都不起作用。如何设置背景颜色?
方法一
<UserControl x:Class="deletewpf.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:deletewpf"
mc:Ignorable="d"
d:DesignStyle="{StaticResource MyDesignStyle}"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<Style TargetType="{x:Type Control}" x:Key="MyDesignStyle">
<Setter Property="Background" Value="White"/>
</Style>
</UserControl.Resources>
<Grid>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
方法二
<UserControl x:Class="deletewpf.UserControl2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:deletewpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<d:DesignerProperties.DesignStyle>
<Style TargetType="UserControl">
<Setter Property="Background" Value="White"/>
</Style>
</d:DesignerProperties.DesignStyle>
<Grid>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
在出现这些错误之前,我已经按下 Run 来构建它。