<Window x:Class="Using_Inherited_Dps.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStartupLocation="CenterScreen"
Title="依赖项属性的继承" Height="400" Width="578" Foreground="Red">
<StackPanel >
<Label Content="熊俊" />
</StackPanel>
</Window>
上面的Lable的字体没有继承Window的Red,不是红色,为什么呢?
解决方案 »
- 五子棋编程对战 博弈树算法 与 alpha-beta剪枝算法 视频讲座下载 欢迎大家编程对战
- C#右截取字符串
- 请教各位大虾,vs2008 代码智能提示前面的小图标的意思?
- XML嵌入资源 急..........在线等待......高分求救
- 关于自定义控件treeview
- 高分求PUSH模式和PULL模式的样板程序!
- 关于往数据库写入信息后进行弹窗的求助
- 求助linq语句
- 在 C# 中,字符串怎么没有 pos 函数。
- 在线求助:打包以后的exe文件如何在没有装.net的windows2000professional环境下运行?
- 【分享交流】ASP.NET MVC多用户博客
- C# 里边使用backgroundWorker,可以像使用Thread一样,设置成STA吗?
<Style x:Key="LabelStyle1"
TargetType="{x:Type Label}">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="Padding"
Value="5" />
<Setter Property="HorizontalContentAlignment"
Value="Left" />
<Setter Property="VerticalContentAlignment"
Value="Top" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="True">
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
DynamicResource {x:Static SystemColors.ControlTextBrushKey}
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Foreground="Red">
<StackPanel >
<Label Content="熊俊" /> <TextBlock Text="12334" />
</StackPanel></Window>TextBlock 是有效果的哦MSDN上是这么写的
This property only affects a control whose template uses the Foreground property as a parameter. On other controls, this property has no impact.
所以对TextBlock可以起作用而CheckBox, Button一类的就不起作用。我们在使用Button的Foreground属性时,实际上也只是对Button内部的TextBlock的Foreground产生了作用,用Snoop查看Button的VisualTree可以发现
Button
Chrome
ContentPresenter
TextBlock也就是Button的内容(字符串)实际上是在TextBlock中被显示出来,并且Foreground属性也是被应用到了TextBlock上。所以LZ还是一个一个设置吧~~~
<LinearGradientBrush>
<GradientStop Color="Green"></GradientStop>
<GradientStop x:Name="gcc1" Color="Green" Offset="0.3"></GradientStop>
<GradientStop x:Name="gcc2" Color="Blue" Offset="0.3"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</LinearGradientBrush>
</TextBlock.Foreground>
你看看这段代码,希望对你有帮助,这是设置的TextBlock的属性颜色,改成Lable就行了
<Label Content="熊俊" Foreground="Red" />
</StackPanel>