views:

29

answers:

1

I have a class called ledgerObject :

public class LedgerObject
{
    public ChargeLine ChargeLine{ get; set; }

    public DelegateCommand Click_hyperbnCommand{ get; private set; }

    public LedgerObject()
    {
        this.Click_hyperbnCommand = new DelegateCommand(click_btn);
    }

    private void click_btn(object args)
    {
    }
}

The chargeLine which is the property of this class is itself a class and has some properties in it.

So I am binding the datacontext of a listbox to an array of LedgerObject, and I want to bind the textblock control defined inside a listboxitem template to the property of a ChargeLine. Any idea or suggestion will help.

I have tried this but not working:

<TextBlock Margin="4 0 4 0" Grid.Column="3" Text="{Binding Path=ChargeLine.SimCode}" TextDecorations="Underline" Foreground="Red" />
+2  A: 

You have to use the ItemsSource-Property of the ListBox instead of the DataContext.

// edit

The reasons are explained here and here in more detail.

gammelgul
Ah! The real problem was hidden in the text of his question! Well played! +1!
Matt Hamilton
Hi gammelgul, it worked but can you just explain why it was not working with the data context.
Malcolm
See the links in the edit.
gammelgul