views:

203

answers:

2

I'm trying to bind the Forderground dependency property to my UIControl, so that it's drawn in the color the user wishes. Since myUiControl.Foderground autocopletes, I thought I could just bin it in the XAML file like this:

{Binding ElementName=rootControl, Path=Forderground}

When debugging VS says it cannot find the source for binding with this DependencyProperty.. but I couldn't figure out why this is..

Also how can I list all dependency properties of an object while debugging?

A: 

Can you confirm that your "rootControl" element is defined earlier in the xaml markup than your Binding holder? Usually the Bindings are bound to the earlier declared elements.

If you mean ImmediateWindow and IntelliSense usage while debugging than each dependency property metadata has usually public static access modifiers. You can for instance type "Control." and observe all the corresponding dependency properties, routed events and attached properties members.

Hope this helps.

Denis Vuyka
i found rootControl in an example and assumed that it meant the root of the UIControl, I'm probably wrong.. However if I just set Path=Forderground it does not work either, but I don't get the .. not found error again
Nils
A: 

UPDATE: If below wasn't enough for you, try downloading this sample and looking at it.

The ElementName needs to be set as the "x:Name" of your root control and the Path needs to be set to the Property on the root element you wish to bind to. Without the name it cannot find the element you are referring to (hence the initial error) and without the Path it doesn't bind to the correct property (check your output at runtime for an error).

Try this:

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid x:Name="root" Background="Green">
    <Button Background="White" Margin="100">
        <TextBlock Background="{Binding ElementName=root, Path=Background}" Text="TESTING TESTING"/>
    </Button>
</Grid>

Lee Roth
this would bind the dependency property called "Background" in the class Window1, right?
Nils
tryed it out and it works, however this is not exactly what i wanted to do. I wanted to create a user control, where you can set parts of the geometry and some colors from outside, when u embed it in xaml.
Nils
I found this project:http://www.codeproject.com/KB/WPF/wpfarrow.aspx However the author does not use XAML in his control and I wonder how you could do this with XAML.
Nils
Where do you want to get the input for your control? Would you know at design time, or only at runtime?
Lee Roth
I've got a sample that might help you that I'll post a link to tomorrow.
Lee Roth
> Would you know at design time, or only at runtime?Not exactly sure now, but probably only at runtime.
Nils
Link added to answer above
Lee Roth
thx! it has even a converter :)
Nils