Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

XAML and binding problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 13 Jun 2007 06:53 GMT
I'm trying to create a subclass of Slider which slide from one color to the
next and has a gradient brush background.
The C# code has 2 new properties: StartColor, EndColor
The XAML code is the following:
==================
<Slider x:Class="TransparencySlider.ColorSlider"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   x:Name="root">
   <Slider.Background>
 <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
  <GradientStop Color="{Binding StartColor, ElementName=root}"
Offset="0.0"/>
  <GradientStop Color="{Binding EndColor, ElementName=root}" Offset="1.0"
/>
 </LinearGradientBrush>
   </Slider.Background>
</Slider>
==================

however at runtime the gradient brush is all white and the log message (in
the output windows) is: "cannot find source element for the binding", i.e.
cannot find 'root', this slider, the control itself.

mmhh... why is that?
what should I write?
I'm running into a wall......
Radek Cerny - 13 Jun 2007 07:56 GMT
Go to codeproject.com, and download everything that Josh Smith has provided
for WPF.  It is quite well explained and demonstrates a heap of features.

> I'm trying to create a subclass of Slider which slide from one color to
> the next and has a gradient brush background.
[quoted text clipped - 23 lines]
> what should I write?
> I'm running into a wall......
Laurent Bugnion, MVP - 13 Jun 2007 21:43 GMT
Hi,

> I'm trying to create a subclass of Slider which slide from one color to
> the next and has a gradient brush background.
[quoted text clipped - 14 lines]
>    </Slider.Background>
> </Slider>

Try the syntax:

{Binding ElementName=root, Path=StartColor}

You don't say if these properties are dependency properties or standard
CLR properties. In the second case, be aware that your binding will be
one-time only, so if you change the properties in code, the change won't
be propagated to the binding. If you want the change to be propagated,
make dependency properties.

HTH,
Laurent
Signature

Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Lloyd Dupont - 14 Jun 2007 02:11 GMT
I dont see the difference between your syntax and my syntax (except that you
permutted the order of ElementName and Path, and I tried, just in case, but
it didn't work)

Anyway, I know it's one shoot, I don't care for now, I would like it to
work, at least!
(And yes the value are initialize before the call to InitializeComponent(),
so that allright)

Signature

Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com

> Hi,
>
[quoted text clipped - 29 lines]
> HTH,
> Laurent
Laurent Bugnion, MVP - 14 Jun 2007 15:31 GMT
Hi,

> I dont see the difference between your syntax and my syntax (except that
> you permutted the order of ElementName and Path, and I tried, just in
> case, but it didn't work)

I just made things explicit, while you left the "Path" implicit. I was
not sure if it could be the problem, apparently not. OK, let's try
something else ;-)

You can debug your bindings like this:
http://geekswithblogs.net/lbugnion/archive/2007/04/02/110622.aspx

(see the chapter "How to find binding errors?")

If that still doesn't help, zip your project and send it to me, I'll
take a look. My email address is genuine.

> Anyway, I know it's one shoot, I don't care for now, I would like it to
> work, at least!
> (And yes the value are initialize before the call to
> InitializeComponent(), so that allright)

HTH,
Laurent
Signature

Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Laurent Bugnion, MVP - 15 Jun 2007 14:43 GMT
Hi,

After asking Microsoft, the "problem" is in fact that you're not
supposed to subclass controls this way, and the symptom in that case was
actually a scope problem.

The problem is related to this post by Microsoft's Kevin Moore:
http://work.j832.com/2007/06/don-subclass-panel-unless-you-making.html

If you intend to subclass a control (in your case, it was a Slider),
then you need to subclass it properly in code behind, and create a XAML
template for it (usually by adding it to generic.xaml). In other cases,
use a UserControl.

HTH,
Laurent

> Hi,
>
[quoted text clipped - 21 lines]
> HTH,
> Laurent

Signature

Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.