可以从C#推送纯XAML吗? [英] Possible to push pure XAML from C#?

查看:89
本文介绍了可以从C#推送纯XAML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在某些问题上绊脚石,从C#创建XAML的标准方法似乎拒绝以我的方式做事,所以我想知道是否存在一种从C#添加包含XAML的字符串的方法,在PHP中使用echo或pring命令转储html的方式.

感谢您的帮助!

-frank

So I''m stumbling upon some issues where the standard way of creating XAML from C# seems to refuse to do things my way, so I was wondering if there were a way to add a string containing XAML from C#, not unlike the way one would in PHP using echo or pring commands to dump html.

thanks for any help!

-frank

推荐答案

这是我的工作:

Here is what I do:

string Xaml= @"<SolidColorBrush xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Color=""AliceBlue""/">;
          StringReader stringReader = new StringReader(Xaml);
          System.Xml.XmlReader xmlReader = new System.Xml.XmlTextReader(stringReader);
          Brush rslt = XamlReader.Load(xmlReader) as Brush;

/// <summary>
      /// Allow the UI dispatcher thread to spin
      /// </summary>
      private static void DoEvents()
      {
          DispatcherFrame frame = new DispatcherFrame(true);
          Dispatcher.CurrentDispatcher.BeginInvoke
              (
                  DispatcherPriority.Background,
                  (SendOrPostCallback)delegate(object arg)
                  {
                      var dispatcherFrame = arg as DispatcherFrame;
                      dispatcherFrame.Continue = false;
                  },
                  frame
              );
          Dispatcher.PushFrame(frame);
      }


所以我出色的D& D好友"Gygaxiss the Fayhunter"刚刚将我发送到: ^ ]

它正是我在寻找的东西,因此对不必要地"张贴内容感到抱歉.


给出完整的解决方案说明:

只需执行以下操作即可:

So my awesome D&D buddy "Gygaxiss the Fayhunter" just sent me to: http://oldschooldotnet.blogspot.com/2008/11/dynamically-dding-xaml-strings-from-c.html[^]

It had exactly what I was looking for so sorry for posting "needlessly".


Giving a fully fledge explaination of the solution:

simply do this:

// create the XAML-code as a string
    string newEllipse = "<Ellipse xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Stroke='Black' Fill='Red' Height='30' Width='30' Margin='10,10,10,10'></Ellipse>";

// Make string valid XML
    XmlReader reader = XmlReader.Create(new StringReader(newEllipse));

// Add the XAML to the design
    RootElementName.Children.Add((Ellipse)XamlReader.Load(reader));


如果不添加"xmlns ...",显然存在命名空间问题.

-frank


Apparently there are namespace issues if one does not add the "xmlns...".

-frank


这篇关于可以从C#推送纯XAML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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