0

我是 Silverlight 中 xml 的新手。我在下面有一个小的 xml 文件

<FlowActivities>

 <SequenceFlow >

  <FlowWriteLine>

         hiiii

  </FlowWriteLine>

 </SequenceFlow>

</FlowActivities>

在这个我想在rootnode.like中硬编码一些命名空间

<FlowActivities x:Class="WorkflowConsoleApplication1.modify" 
      xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" 
      mc:Ignorable="sap2010"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#"
      xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
      xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"   
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

 <SequenceFlow >

  <FlowWriteLine>

         hiiii

  </FlowWriteLine>

 </SequenceFlow>

</FlowActivities>

为了得到这个我必须做的事情..?请解决这个问题..?

4

2 回答 2

1

You can't. You have to set the variable like JoanComasFdz said. If you must use the same format, you can create a separate class(viewmodel) for eg. MyXMLData.cs to read and parse xml file. Read the XML node and set the class variable "theString" from this class. In XAML, you can create an instance of the class in the resources section and set the data context of the Grid or the textbox to that object.

<UserControl
    x:Class="Test_SL_HardcodeString.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:system="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d"
    xmlns:viewmodel="clr-namespace:MyNameSpace.ViewModels"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <UserControl.Resources>
        <viewmodel:MyXMLData x:key="myxmldataclass"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource myxmldataclass}" >
        <TextBox Text="{StaticResource theString}"/>
    </Grid>
</UserControl>
于 2013-01-24T09:10:34.823 回答
1

XAML 不是当前的 XML 文件,是一种基于 XML 的语言。因此,您不能编写随机的、不存在的 XML 标记。

在 SL XAML 文件中硬编码字符串:

<UserControl
    x:Class="Test_SL_HardcodeString.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:system="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <UserControl.Resources>
        <system:String x:Key="myString">This is a test string</system:String>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox Text="{StaticResource myString}"/>
    </Grid>
</UserControl>
于 2013-01-24T08:49:15.307 回答