Silverlight中资源文件的引用

1、新建一个资源文件,比如: Gaugestyle.xamlMenuButton.xaml


2、在App.xaml中添加该资源:

<Application
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="spjl1.App">
	<Application.Resources>
		<!-- Resources scoped at the Application level should be defined here. -->
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="Gaugestyle.xaml"/>
				<ResourceDictionary Source="MenuButton.xaml"/>
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</Application.Resources>
</Application>

3、在页面文件后台中使用:

 ResourceDictionary resources = new ResourceDictionary();
 resources.Source = new Uri("/spjl1;component/MenuButton.xaml", System.UriKind.Relative);
 RadWindow1.Style = resources["ChildWindowStyle1"] as Style;

 

=====================================================内容补充======================================================

这里用一个Label的资源样式文件LabelStyle.xaml来讲解:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!--添加面板·标题-->
    <Style x:Key="tbAddTitle" TargetType="{x:Type Label}">
        <Setter Property="FontFamily" Value="Microsoft YaHei" />
        <Setter Property="Height" Value="28" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="Foreground" Value="#FF0000" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
    </Style>
</ResourceDictionary>

 

将该资源样式文件添加到App.xaml中

<Application
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="spjl1.App">
	<Application.Resources>
		<!-- Resources scoped at the Application level should be defined here. -->
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="LabelStyle.xaml"/>
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</Application.Resources>
</Application>




如果在前台XAML中使用,使用Style属性,方式如下:

  <TextBlock Foreground="Black" Margin="0,1,479,0" Name="textBlock1" Style="{StaticResource tbAddTitle}" Text="供货商名称:" Grid.ColumnSpan="2" />



 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值