微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐