zoukankan      html  css  js  c++  java
  • Silverlight 点滴(一) 获取定义在Generic.xaml或其他*.xaml中的对象

    运行环境: Silverlight 3.0(未在2.0下面做过测试,貌似本方法不支持2.0,因为2.0下面,ResourceDictionary没有Source属性)

    ResourceDictionary resources = new ResourceDictionary();
    resources.Source 
    = new Uri("/Cinlap.UI.SL.Controls;component/Themes/Generic.xaml", System.UriKind.Relative);

    ControlTemplate controlTemplate 
    = resources[templateName] as ControlTemplate;

    只要将ResourceDictionary.Source属性设置为合适的Uri,则可以通过Key来获取需要的对象。

    补充:刚才又发现一个利用ResourceDictionary的场景
    在创建自定义控件时,我们有可能需要在Generic.xaml中定义多个控件的Style,定义的多了找起来就很麻烦,如果在单个文件里定义好,然后在Generic.xaml中包含(include)岂不是很好,看到了Telerik.RedControl For Silverlight中使用了<?include(***.xaml)?>式语句,但始终没有找到如何实现该功能,无奈,只得找其他的方式,终于发现使用ResourceDictionary.Source也能实现同样功能,Generic.xaml代码如下:

    <ResourceDictionary
        
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml">

        
    <ResourceDictionary.MergedDictionaries>
            
    <ResourceDictionary Source="/Cinlap.UI.SL.Controls;component/Themes/DockPanel.xaml"/>
        
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

    显而易见,此方法也是在一个xaml文件中包含另一个xaml文件的方法。
  • 相关阅读:
    9.6、Libgdx之罗盘
    9.5、Libgdx加速度计
    9.4、Libgdx简单字符输入
    9.3、Libgdx手势检测
    9.2.2、Libgdx的输入处理之事件处理
    9.2.1、Libgdx的输入处理之轮询
    基于ip的虚拟主机配置——在一台服务器上绑定多个 IP 地址
    解决Nginx出现403 forbidden
    SpringMVC中JSONP的基本使用
    centOS7 tomcat 开机自启 自启动设置
  • 原文地址:https://www.cnblogs.com/think8848/p/1542420.html
Copyright © 2011-2022 走看看