Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Databinding not working on Borders ?

 
 
Old 05-18-2006   #1 (permalink)
jods


 
 

Databinding not working on Borders ?

I am trying to databind a color to a Border control.
The goal is to have the border as 100% opaque and the background filled with
the same color, but with only 10% opacity.

Here's the relevant XAML:

<Border BorderThickness="2" Padding="2">

<Border.BorderBrush>
<SolidColorBrush Color="{Binding Owner.Color}" />
</Border.BorderBrush>

<Border.Background>
<SolidColorBrush Color="{Binding Owner.Color}" Opacity="0.1" />
</Border.Background>

....

Now the result is really confusing. The Background is filled correctly, but
the border is transparent!!!

I see 2 things which could go wrong:
1. The databinding is not working (wrong Path, null object, whatever). But
this is obviously not the case, since the Background - which uses the very
same binding - is working perfectly!
2. The BorderBrush doesn't work like I think it does. But just replacing the
binding expression with a constant "Red" works flawlessly. So it's probably
alright too.

Can you guess what can go wrong with such a simple example ? Is this a bug
in WPF ?

My System SpecsSystem Spec
Old 05-18-2006   #2 (permalink)
Douglas Stockwell


 
 

Re: Databinding not working on Borders ?

I can't see why that doesn't work.

My guess is 1. Are you seeing any binding errors in the output?

Is the background that is being drawn possibly from the control inside the
border?

Something like this would allow you determine if the background is actually
being set correctly. (following is tested)

<Border BorderThickness="2" Padding="2" Name="Border">
<Border.BorderBrush>
<SolidColorBrush Color="{Binding ElementName=Border, Path=Background.Color}"
/>
</Border.BorderBrush>

- Doug

> I am trying to databind a color to a Border control.
> The goal is to have the border as 100% opaque and the background
> filled with
> the same color, but with only 10% opacity.
> Here's the relevant XAML:
>
> <Border BorderThickness="2" Padding="2">
>
> <Border.BorderBrush>
> <SolidColorBrush Color="{Binding Owner.Color}" />
> </Border.BorderBrush>
> <Border.Background>
> <SolidColorBrush Color="{Binding Owner.Color}" Opacity="0.1" />
> </Border.Background>
> ....
>
> Now the result is really confusing. The Background is filled
> correctly, but the border is transparent!!!
>
> I see 2 things which could go wrong:
> 1. The databinding is not working (wrong Path, null object, whatever).
> But
> this is obviously not the case, since the Background - which uses the
> very
> same binding - is working perfectly!
> 2. The BorderBrush doesn't work like I think it does. But just
> replacing the
> binding expression with a constant "Red" works flawlessly. So it's
> probably
> alright too.
> Can you guess what can go wrong with such a simple example ? Is this a
> bug in WPF ?
>



My System SpecsSystem Spec
Old 05-19-2006   #3 (permalink)
jods


 
 

Re: Databinding not working on Borders ?

Thank you for the suggestion.

Unfortunately, binding the border directly to the background doesn't seem to
work either. I guess that there is something broken in the databinding
mechanism.

I indeed see one error in the output, but I can't figure out what it means:

Cannot find mentor for target element.
'BindingExpression':Path='Owner.Color'; DataItem=''null'';
target element is ''SolidColorBrush' (hashcode='18783768')'; target
property is 'Color' (type 'Color');

What surprises me most is the DataItem="null" ?? I mean: the background IS
working, isn't it ? And what is this "mentor" ?

BTW, I've tried another workaround (which doesn't work either). I wanted to
directly databind the BorderBrush attribute:
<Border BorderBrush="{Bind Owner.Color}" ...>
A message in the output indicates that it doesn't work because there's no
default converter from Color to Brush (of course). But the message clearly
indicates that the binding is working:
'#FF008000' value produced by BindingExpression is not valid for target
property

I'm clueless.
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Borders in Excel PowerShell
Printing borders Vista print fax & scan
Touchpad Corners & Borders Vista General
Program borders Vista General
Transparent Windows - Not Borders???? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46