I want to load data from XML file which is in IsolatedStorage. Then I have in variable specific index number which is XML element index. And here I have a problem, because I want to load in TextBoxes (in normal StackPanel) values from this element. I tried with binding and putting this in listbox but then I cannot read text from this boxes, cause it’s listbox items. Simply I want to load element attributes to TextBoxes and after it I want to read edited text in this textboxes.
This is example xml element:
<person index="1" att1="qwerty" att2="azerty" att3="abcdef"/>
This is Xaml code:
<StackPanel x:Name="stack">
<TextBlock Height="27" Margin="0,0,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Record index:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox Text="{Binding Index}" x:Name="index_box_det" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
</StackPanel>
I have tried this:
var ind = "1";
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Open, isoStore))
{
XDocument loadedCustomData = XDocument.Load(isoStream);
var filteredData = from c in loadedCustomData.Descendants("person")
where c.Attribute("index").Value == ind
select new Person()
{
index= c.Attribute("index").Value,
att1= c.Attribute("att1").Value,
att2= c.Attribute("att2").Value,
att3= c.Attribute("att3").Value
};
stack.DataContext = filteredData;
}
But as you think, it does not work. Somebody have idea to load this values to textboxes ?
EDIT:
I have tried this:
var ind = "1";
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Open, isoStore))
{
XDocument loadedCustomData = XDocument.Load(isoStream);
var filteredData = from c in loadedCustomData.Descendants("person")
where c.Attribute("index").Value == ind
select new Person()
{
index= c.Attribute("index").Value,
att1= c.Attribute("att1").Value,
att2= c.Attribute("att2").Value,
att3= c.Attribute("att3").Value
};
stack.DataContext = filteredData;
}
index_box_det.Text = Index;
Still not works.
You must invoke
FirstOrDefaultmethod:Personclass: