Hi, I have a silverlight application, and I need to recover the values of several textboxes within a listbox. Theese textboxes are created in the Page.xaml like the following:
You are using data binding. If you set TwoWay binding for the TextBox, the value user entered in the box should be automatically update the DataObject that bind to that row.
If you check the Nome field on you DataObject in the ProgrammazioneDS, you should be able to see the change. You do not need to access the UI element to retrieve that data.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
I've setted the Binding mode in TwoWay, but I don't know how to access the ProgrammazioneDS to check the value of Nome. My DataObject is an ObservableCollection<Palinsesto>, and it is used in a class added to the project (Palinsesto.cs). I need to recover
the text values in my Page.xaml.cs.
I've also tried to use the DataContext, but its value is null... [:(]
Frank87
Member
5 Points
59 Posts
Recover text value (Silverlight application)
Oct 08, 2008 03:35 PM | LINK
Hi, I have a silverlight application, and I need to recover the values of several textboxes within a listbox. Theese textboxes are created in the Page.xaml like the following:
<ListBox Margin="23,8,23,23" ItemsSource="{Binding '', Mode=OneWay, Path=ProgrammazioneCompleta, Source={StaticResource ProgrammazioneDS}}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.RowSpan="3" Grid.Column="1" Grid.Row="1" x:Name="ListBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="2">
<TextBlock Text="{Binding Ora}"/>
<TextBlock Text=" - "/>
<TextBox Text="{Binding Nome}" BorderBrush="Transparent" BorderThickness="0"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In my Page.xaml.cs I can see the listbox, but not the textboxes .How can I recover the text value of the textboxes ??
Thanks for the help ;)
HarshBardhan
Star
10118 Points
1749 Posts
Re: Recover text value (Silverlight application)
Oct 08, 2008 03:40 PM | LINK
Hi,
If your Binding mode is two way you can get that in your DataContext.
Harsh Bardhan
sladapter
All-Star
43609 Points
7910 Posts
Re: Recover text value (Silverlight application)
Oct 08, 2008 03:45 PM | LINK
You are using data binding. If you set TwoWay binding for the TextBox, the value user entered in the box should be automatically update the DataObject that bind to that row.
<TextBox Text="{Binding Nome, Mode=Two Way}" BorderBrush="Transparent" BorderThickness="0"/>
If you check the Nome field on you DataObject in the ProgrammazioneDS, you should be able to see the change. You do not need to access the UI element to retrieve that data.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Frank87
Member
5 Points
59 Posts
Re: Recover text value (Silverlight application)
Oct 13, 2008 08:44 AM | LINK
I've setted the Binding mode in TwoWay, but I don't know how to access the ProgrammazioneDS to check the value of Nome. My DataObject is an ObservableCollection<Palinsesto>, and it is used in a class added to the project (Palinsesto.cs). I need to recover the text values in my Page.xaml.cs.
I've also tried to use the DataContext, but its value is null... [:(]
HarshBardhan
Star
10118 Points
1749 Posts
Re: Recover text value (Silverlight application)
Oct 13, 2008 11:09 AM | LINK
Hi,
you can try with something like this.
I did that on mouse down handler.
Person p = (Person)this.DataContext;//Here Person is my Object with which i bounded my userControl
Harsh Bardhan
Frank87
Member
5 Points
59 Posts
Re: Recover text value (Silverlight application)
Oct 13, 2008 04:03 PM | LINK
I've tried to convert the DataContext, but it still remains null...
I try to exlpain what happens:
_ I read from an xml file, and write its content in a series of textblocks and textboxes, within a listbox:
(this is Palinsesto.cs file)
_ Once I have the listbox filled, I have to write the content of the texboxes in the xml file, on the click event button;
(this is Page.xaml.cs file)
neal.gabriel
Contributor
4520 Points
789 Posts
Re: Re: Recover text value (Silverlight application)
Oct 13, 2008 07:09 PM | LINK
Hi,
If you need to get the values from a list, you need to create an object for that and loop it.
Eg:
Here is your Class Object which has all the data
Palinsesto pippo = (Palinsesto)array
What you have to do is as follows
foreach(var oPippo in pippo)
{
strNome = oPippo.Nome;
}
HTH
Neal Gabriel
Neal Gabriel
Follow me on twitter
My Blog
HarshBardhan
Star
10118 Points
1749 Posts
Re: Recover text value (Silverlight application)
Oct 14, 2008 07:09 AM | LINK
Hi,
You are almost there.
You have to cast that to appropriate object and loop throgh it.
Harsh Bardhan
Frank87
Member
5 Points
59 Posts
Re: Recover text value (Silverlight application)
Oct 14, 2008 08:10 AM | LINK
Now it works !! ..Thank you very much guys !! [:D]