我是silverlight.i中的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>为了得到我必须要做的..?请把这件事弄清楚..?
发布于 2013-01-24 16:49:15
XAML不是当前流行的文件,而是一种基于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-24 17:10:35
你不能。你必须像JoanComasFdz说的那样设置变量。如果你必须使用相同的格式,你可以为例如创建一个单独的类(Viewmodel)。读取和解析xml文件的MyXMLData.cs。读取XML节点并从该类中设置类变量"theString“。在XAML中,您可以在资源部分中创建类的实例,并将Grid或textbox的数据上下文设置为该对象。
<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>https://stackoverflow.com/questions/14495569
复制相似问题