Skip to main content

Microsoft Silverlight

Answered Question Simple Textbox binding?!?!RSS Feed

(0)

j_mcmullan
j_mcmullan

Member

Member

2 points

16 Posts

Simple Textbox binding?!?!

Hello fellow Silverlighters,

 I'm hoping that somebody here will be able to shed some light on my problem. From everything I've read this really should be very simple but I can't get it to work!

 I have a DomainDataSource:

<riaControls:DomainDataSource x:Name="ddsLearnerProfile"
AutoLoad ="True"
QueryName="GetStaticAOSWithLearnerProfile">
<riaControls:DomainDataSource.DomainContext>
ds:eIQRSContext/>
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaData:Parameter ParameterName="theStaticAOSCode" Value="70162"/>
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>

Now all I want to do is bind a value to a Textbox (txtOtherFactors).

<Grid Margin="0,0,-111,8" Grid.Row="1" Grid.ColumnSpan="3" DataContext="ddsLearnerProfile">
<Grid.RowDefinitions>
<RowDefinition Height="0.101*"/>
<RowDefinition Height="0.899*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.014*"/>
<ColumnDefinition Width="0.986*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="textBlock" Text="Other factors/interests of group" TextWrapping="Wrap" Grid.Column="1" HorizontalAlignment="Left" Width="189" Margin="0,0,0,0"/>

<TextBox x:Name="txtOtherFactors" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" Margin="0,8,20,30" AcceptsReturn="True" Text="{Binding StaticAOSTitle}"/>

<Button x:Name="btnLPSave" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="75" Content="Save" Margin="0,0,144,0" Grid.Column="1" Grid.Row="1" Click="btnLPSave_Click" />
</Grid>

The DataContext is set on the parent grid. I have verified that I'm getting data back by binding the whole entity to a datagrid with autogenerating columns but I cannot get it to bind to the Textbox. Any help or suggestions would be greatly appreciated!

Thanks in advance,

Jonny

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Re: Simple Textbox binding?!?!

The DDS is exposing a collection of entities. The TextBox does not know how to bind to a collection of entities, so you need some other object (such as the DataGrid) to break the collection down into individual entities.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

j_mcmullan
j_mcmullan

Member

Member

2 points

16 Posts

Answered Question

Re: Re: Simple Textbox binding?!?!

Hi Colin,

Firstly thanks, for the quick reply. If I'm only returning one record can I not bind directly to a specific "column"?

If I can't do that then, would I be best to use something like a dataFormToolkit:DataForm, I don't know much about this control but from what little I've read it might let me bind to the textboxes?

Thanks,

 Jonny

FuryDiamond
FuryDiamond

Contributor

Contributor

3870 points

766 Posts

Re: Re: Re: Simple Textbox binding?!?!

If it is just a single item, you can simply set the value directly in the code rather than data binding.  On the TextBox, you can then add TextChanged to update the data back to the source.

Or you could use a DataConverter along with your data binding to parse the data accordingly.

Please "Mark as Answer" if this post answered your question. :)

j_mcmullan
j_mcmullan

Member

Member

2 points

16 Posts

Re: Re: Re: Simple Textbox binding?!?!

Hi all,

So it turns out that I needed to use a dataFormToolKit:DataForm. Now I'm able to bind my textboxes to my dds! Big Smile

Thanks to Colin for pointing me in the right direction!

Jonny

pattormey
pattormey

Member

Member

35 points

18 Posts

Re: Re: Re: Simple Textbox binding?!?!

Hi FuryDiamond,

I have the same issue. BUT I don't want to use the RIA DataForm.

I've got a layout I like and just need to write up the bindings.

I am returning a List<MyData> but it will typically ocontain one item representing a new record. Later people will need to flip thru MyData 'record' using the List<MyData>

So it sounds like I need your suggestion to use a DataConverter to parse the data. That seems like a lot of work to get the one element in the list to be the current item.

Whenever I find myself working too hard I think I'm missing something (g).

So the simple question is.... IF I return a List of Items how can I bind the first one to a text box when NOT using the RIA Data Form.

Seems like I shoud bind to List[0] to display one at a time but I'm new to this so I don't understand.

 Can you point me in the right direction?

Thanks

 

 

 

Pat Tormey PE
MS MVP
New Hampshire USA
PTormey@4square.net
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities