![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | XAML and binding problem 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...... |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: XAML and binding problem 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. "Lloyd Dupont" <net.galador@ld> wrote in message news:uQI2Q9XrHHA.3484@TK2MSFTNGP05.phx.gbl... > 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...... |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: XAML and binding problem Hi, Lloyd Dupont wrote: > 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> 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 -- 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 |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: XAML and binding problem 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) -- Regards, Lloyd Dupont NovaMind Software Mind Mapping at its best www.nova-mind.com "Laurent Bugnion, MVP" <galasoft-lb@bluewin.ch> wrote in message news:eKaS$tfrHHA.5028@TK2MSFTNGP05.phx.gbl... > Hi, > > Lloyd Dupont wrote: >> 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> > > 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 > -- > 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 |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: XAML and binding problem Hi, Lloyd Dupont wrote: > 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/a...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 -- 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 |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: XAML and binding problem 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-sub...ou-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 Laurent Bugnion, MVP wrote: > Hi, > > Lloyd Dupont wrote: >> 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/a...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 -- 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 |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binding an ImageBrush Problem | star-italia | .NET General | 5 | 06-13-2008 02:36 AM |
| Accessing an Array element(i) from a XAML "binding path" | iterationx | Avalon | 1 | 03-23-2007 11:17 AM |
| XAML Binding / Animated Expander | gregbacchus@hotmail.com | Avalon | 1 | 03-14-2007 04:57 AM |
| XAML and binding to datatables (ADO.net) | Magne | Avalon | 4 | 01-03-2007 11:10 PM |
| XAML binding between controls? | CosminB [BRT] | Avalon | 11 | 04-19-2006 11:39 AM |