Reputation: 892
i am new to xml in silverlight.i have one small xml file below
<FlowActivities>
<SequenceFlow >
<FlowWriteLine>
hiiii
</FlowWriteLine>
</SequenceFlow>
</FlowActivities>
in this i want to hardcode some namespace in 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>
for getting this wht i have to do..? pls sort this out..?
Upvotes: 0
Views: 489
Reputation: 1124
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>
Upvotes: 1
Reputation: 3066
XAML is not a current XML file, is a language based on XML. Therefore you can not write random, non-existent XML tags.
To hardcode a string in SL XAML file:
<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>
Upvotes: 1