One-Way Binding (WPF&XAML)

Page 1 of 1

2 Replies - 2693 Views - Last Post: 22 May 2012 - 07:17 AM Rate Topic: -----

#1 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 114
  • Joined: 17-March 10

One-Way Binding (WPF&XAML)

Posted 22 May 2012 - 04:15 AM

Hi there Gurus.

I am new to WPF and XAML, so my question should be an easy one...

Now, i have a simple class:
public class EditionListSummary
{
    public int editionCounter { get; set; }
}



I then assign value to that editionCounter property (in another class)
EditionListSummary edSummary = new EditionListSummary();
edSummary.editionCounter = ultimaPrintRow.EditionList.Count;



I get my editionCounter property populated the way i need.

Now the problem: i try to bind that class property to a TextBlock Text property, but no luck :(
<TextBlock Name="eCounter" Text="{Binding Path=editionCounter}" Grid.Column="0">



Internet is full of examples that somehow not working for me.
Maybe the easiest way is to populate Text property of my TextBlock from CodeBehind via TextBlock name? If so, please give me a tip, because at the moment i have no access from C# to the FixedDocument of the DocumentViewer in XALM.

Thank You in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: One-Way Binding (WPF&XAML)

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: One-Way Binding (WPF&XAML)

Posted 22 May 2012 - 05:01 AM

You also need to add this line of code.

this.DataContext = edSummary;



The binding is correct in XAML, but the XAML doesn't know where editionCounter is. By setting the DataContext of the window, the binding will look there to see if it has a property named editionCounter.

All FrameworkElements(basically anything that can be put in XAML) have a DataContext property.
Was This Post Helpful? 2
  • +
  • -

#3 c#think#:)  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 114
  • Joined: 17-March 10

Re: One-Way Binding (WPF&XAML)

Posted 22 May 2012 - 07:17 AM

Thank you eclipsed4utoo!

And yes, i have figured it out and came back to post my results which you have already did :)

Thank you once again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1