从磁盘加载XAML文件,并将其与项目一起添加. [英] Load a XAML File From disk and add it with the Project.

查看:78
本文介绍了从磁盘加载XAML文件,并将其与项目一起添加.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海伊之友..


是否可以按原样加载XAML文件并使其成为UI,但不能在运行时将其内容加载到另一个文件中.我在运行时遇到了与XAML内容配合使用的解决方案.XAMLWRITER和READER可以完成工作.

这是用于创建XAML的代码..但是我必须将CS文件与XAML一起添加,并且在运行时需要将其加载到一起.有人可以帮助我..也可以将CS文件分别保存为在运行时链接它们..
谢谢..

解决方案

Anish ....该演示代码扩展了TextBlock并从字符串构建了一个新的TextBlock(不需要代码文件):

 公共  class  TextoRecurso:TextBlock
{
  公共 字符串
  {
    设置
    {
      Inlines.Clear();
      文字= 如果( == )返回;
      StringBuilder SB =  StringBuilder();
 
      SB.Append("  \  "  "   textblock  >  " 




This is the code am using to create XAML.. but i have to Add CS file along with XAML and at run time i need to load it together.Can Anybody help me.. and also is it possible to keep the cs file Separately and link them at run time..
Thank you..

解决方案

Hi Anish.... this demo code extends TextBlock and builds a new TextBlock from a string (no code file needed):

public class TextoRecurso : TextBlock
{
  public string Recurso
  {
    set
    {
      Inlines.Clear();
      Text = null;
 
      if (value == null) return;
      StringBuilder SB = new StringBuilder();
 
      SB.Append("<textblock xmlns="\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"">");
      SB.Append(value);
      SB.Append("</textblock>");
 
      var TB =
        XamlReader.Load(new System.Xml.XmlTextReader(
          new System.IO.StringReader(SB.ToString()))) as TextBlock;
      var Lista = TB.Inlines.ToArray();
 
    }
  }
}


这篇关于从磁盘加载XAML文件,并将其与项目一起添加.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆