views:

141

answers:

2

Where can I find some good documentation on data/element binding? My Google searches haven't turned much up. I had a custom class with two properties named Text and Value. When I tried binding a list to a listbox it wouldn't work. By chance I modifed my datatemplate from this

<TextBox Text="{Binding Text}"></TextBox>

to this

<TextBox Text="{Binding Path=Text}"></TextBox>

and then everything worked great. I need some indepth documenation/samples to data/element binding. I don't understand why some examples have the path set whereas others do not. A full explanation of this, and all other nice to know tips would be much appreciated.

UPDATE

Here's the class I'm using. It's a simple helper class so I can translate the value/text of an enum into my listbox

public class Item
{
    private string _Text = "Test";
    public string Text
    {
        get { return _Text; }
        set { _Text = value; }
    }

    private string _Value = "1";
    public string Value
    {
        get { return _Value; }
        set { _Value = value; }
    }
}
+2  A: 

Not much, but here's a little to get you started:

MSDN documentation is here: http://msdn.microsoft.com/en-us/library/cc278072(VS.95).aspx

This page explains paths in slightly more detail: http://msdn.microsoft.com/en-us/library/system.windows.data.binding.path.aspx

As for why your example only works with the Path clause, I'll need to see the class you're binding to.

Sheeo
I've made an update with my simple class. Thanks for your post too!
Matt
+1 For http://msdn.microsoft.com/en-us/library/cc278072(VS.95).aspx
DaveB
Just fired it up in VS. Both your examples on top work for me. From what I understand, the Path clause is for more complex navigation of methods/properties (I.e. whatever they might throw at you), whereas the normal binding is just a property.
Sheeo
+1  A: 

In theory, your two binding examples are equivalent. The Path= is optional if your path is the first part of the Binding clause, so if one of your examples behaved differently, it's either due to a bug in Silverlight or a change you made elsewhere without realizing it.

Here's the Silverlight documentation on Path: http://msdn.microsoft.com/en-us/library/cc645024(v=VS.95).aspx

Here's the Silverlight documentation for {Binding}: http://msdn.microsoft.com/en-us/library/cc189022(VS.95).aspx

Gabe