Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I create a windows phone application.i have a textbox i want to put the text from xml file.Ihave an error cant convert systemCollectionGenric en String how cani solve this thanks
this is my textbox definition en XAML.
<textbox x:name="Nom" width="371" margin="0,496,0,0" height="90" verticalalignment="Top" xmlns:x="#unknown">


and this my xml file

XML
<Chart>
  <chart>SerialChart</chart>
  <title>Title</title>
  <CategoryValueMemberPath>month</CategoryValueMemberPath>
  <AxisForeground>White</AxisForeground>
  <PlotAreaBackground>Black</PlotAreaBackground>
  <GridStroke>Green</GridStroke>
  <Graph>Line</Graph>
  <Title>Title</Title>
  <ValueMemberPath>actual</ValueMemberPath>
  <Brush>green</Brush>
  <Brush>red</Brush>
</Chart>




this is my code behind
C#
InitializeComponent();
XDocument loadedData = XDocument.Load("XML.xml");

var data = from query in loadedData.Descendants("Chart")
           select new Person
           {
               FirstName = (string)query.Element("title"),
               LastName = (string)query.Element("Graph"),
               Age = (int)query.Element("StrokeThickness")
           };
Nom.Text = data;
Posted
Comments
[no name] 13-May-14 19:01pm    
It means exactly what it says. Your query is returning a collection and you are trying to stuff a collection into something that expects a string.
Ahmed Hammami 14-May-14 3:47am    
yes how can i do this thnks
[no name] 14-May-14 8:58am    
Sorry but I am unable to read your mind at this time to know what "this" is that you are trying to do.

1 solution

Hello,


It should be used in the Value property of the query result, instead regarding the query string value is converted to an integer

C#
InitializeComponent();
XDocument loadedData = XDocument.Load("XML.xml");
 
var data = from query in loadedData.Descendants("Chart")
           select new Person
           {
               FirstName = query.Element("title").Value,
               LastName = query.Element("Graph").Value,
               Age = Int.Parse(query.Element("StrokeThickness").Value)
           };
Nom.Text = data;



Bye.
 
Share this answer
 
Comments
Christian Amado 27-Aug-14 13:45pm    
The right answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900