【问题标题】:Load element from external file从外部文件加载元素
【发布时间】:2012-06-22 03:26:52
【问题描述】:

我想从外部文件加载 WPF 元素。示例我有一个文件brush.xaml,如下所示:

<SolidColorBrush>Black</SolidColorBrush>

我想在我的代码中加载这个画笔:

using(FileStream stream = new FileStream("brush.xaml"))
  Brush myBrush = XamlReader.Load(stream) as Brush;

我该怎么办?

【问题讨论】:

    标签: c# wpf xamlreader


    【解决方案1】:

    您的代码是正确的,但在 xaml 文件中使用:

    <SolidColorBrush xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
       #FF0000
    </SolidColorBrush>
    

    采用十六进制格式。无论如何,如果您有任何疑问,您可以使用XamlWriter 进行测试。

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 不,我需要像我写的那样加载它来解析 XAML。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2012-12-06
      相关资源
      最近更新 更多