0

I had bind my textblock in xaml, is it possible to get the value out into my coding?

My coding for binding

<TextBlock Height="40" HorizontalAlignment="Left" Margin="8,24,10,0" Name="txtBlockCustName" Text="{Binding CustName, Mode=OneWay}" VerticalAlignment="Top" FontSize="26" />

I want to put in my mainpage.xaml.cs like

string CustName = txtBlockCustName.Text;

but it had error on it..

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65
Brownie yeo
  • 126
  • 2
  • 12
  • Perhaps http://stackoverflow.com/a/4364974/296526 is what you are looking for. – Myrtle Jun 18 '12 at 19:18
  • It does not exist in the current content. – Brownie yeo Jun 18 '12 at 19:40
  • What is the scope for the text block? Is it inside a container or grid? What is the data context set to? Basically CustName must be implemented as a property on the object where the data context is set. What you have done above is tried to create a circular reference. I would take a look at the data binding for XAML. – tsells Jun 19 '12 at 01:25
  • inside a listbox data template..isit can binding textblock without using listbox data template? – Brownie yeo Jun 19 '12 at 03:36

1 Answers1

0

You can't access this textblock because it is bound in a listboxtemplate. If there are multiple textblocks in the list, how can you access it by name? The program won't know what textblock you are asking for. This is why an error is thrown.

You could use the collection that you bound to the listbox to get the customer name.

Alex Bettadapur
  • 118
  • 1
  • 8