读书人

WPF请教这个资源如何引用

发布时间: 2013-11-06 16:26:37 作者: rapoo

WPF,请问这个资源怎么引用?


<Window.Resources>
<Button x:Key="aa" Background="Red"/>
</Window.Resources>
<Grid>

</Grid>


上面有一个button资源,请问,在Grid里面,如何引用资源,并设置button的Foreground属性。
[解决办法]
你应该这么干:

 <Window.Resources>
<!--<Button x:Key="aa" Background="Red" -->
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red"></Setter>
</Style>
</Window.Resources>
<Grid>
<Button Content="Test" ></Button>
</Grid>

读书人网 >C#

热点推荐