Silverlight中资源文件的引用

Silverlight中资源文件的引用,第1张

概述1、新建一个资源文件,比如: Gaugestyle.xaml和MenuButton.xaml 2、在App.xaml中添加该资源: <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xa

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

以上是内存溢出为你收集整理的Silverlight中资源文件的引用全部内容,希望文章能够帮你解决Silverlight中资源文件的引用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1073712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存