Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

XAML and binding problem

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-13-2007   #1 (permalink)
Lloyd Dupont
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 SpecsSystem Spec
Old 06-13-2007   #2 (permalink)
Radek Cerny
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 SpecsSystem Spec
Old 06-13-2007   #3 (permalink)
Laurent Bugnion, MVP
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 SpecsSystem Spec
Old 06-13-2007   #4 (permalink)
Lloyd Dupont
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 SpecsSystem Spec
Old 06-14-2007   #5 (permalink)
Laurent Bugnion, MVP
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 SpecsSystem Spec
Old 06-15-2007   #6 (permalink)
Laurent Bugnion, MVP
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com 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 2005-2008

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 47 48 49 50 51