views:

1863

answers:

12

I'm getting all learned up about binding in WPF. I'm having a lot of trouble debugging the parse errors in my xaml, though. Can somebody pretty please tell me what's wrong with this little piece? :

<Border Name="TrackBackground"
                    Margin="0"
                    CornerRadius="2"                     
                    Grid.Row="1"
                    Grid.Column="1"
                    Background="BlanchedAlmond"
                    BorderThickness="1"
                    Height="{TemplateBinding Height}">

                <Canvas Name="PART_Track" Background="DarkSalmon" Grid.Row="1" Grid.Column="1">
                    <Thumb Name="ThumbKnob" Height="{Binding ElementName=Part_Track, Path=Height, Mode=OneWay}" />
                </Canvas>
            </Border>

It's the databinding that breaks. I get an InvalidAttributeValue exception for ThumbKnob.Height when I try to run this. I know I must be missing something fundamental. So fill me in, stackers, and my gratitude will be boundless.

A: 
Arcturus
A: 

Changing the ElementName didn't help. There must me something else I'm not getting.

I should mention that I'm testing this in Silverlight. The exact message I'm getting out of Internet Explorer is:

XamlParseException: Invalid attribute value for property Height.

This whole thing is inside a ControlTemplate. I'm making a slider control just to teach myself the concepts.

MojoFilter
A: 

Is the Border in a Template btw ?

Because there is no need for TemplateBinding if the border is not located in a Template (either ControlTemplate or DataTemplate)

Arcturus
+1  A: 

What I usually do to debug databindings, is add a converter where I can set a breakpoint in VS.NET..

so the Binding would be something like this:

{Binding ElementName=PART_Track, Path=Height, Mode=OneWay, Converter={StaticResources DebugConverter}}

Then the converter can be an empty implementation of an IValueConverter, set a breakpoint in the Convert method and see what the Height is being set to...

Don't forget to add your converter to your Resources...

Perhaps the value is NaN ?

Arcturus
A: 

I like the converter trick. That's pretty slick. Unfortunately, it's not even getting far enough to get tripped up there. It's actually dying when the xaml is being parsed in the first place.

MojoFilter
+1  A: 
Arcturus
A: 

@arcturus Ah, I was afraid that might be the case. Is it possible Silverlight doesn't support that binding syntax at all?

MojoFilter
+2  A: 

The ElementName property on a Binding is not supported in Silverlight.

You will notice, if you go into the code behind or inspect the Binding object in class explorer, it doesn't have a property named ElementName.

Brian Leahy
Just to note: it is in Silverlight 4. (And 3.5, I think)
MojoFilter
+1  A: 

Ok, here's the deal:

In silverlight, you can't bind values from one UI element to another declaratively. The only way to do what I was trying to do here would be in the C# code.

I had a reference for this yesterday, but now I guess you'll just have to take my word for it :)

MojoFilter
A: 

Hmm ok.. good to know :)

Arcturus
A: 

Silverlight 3 now includes ElementName binding...

Jason Roberts