Click here to Skip to main content
15,905,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hy guys, can You help me on this?

I'm using Silverlight 4 and VS 2010.

I've created a very simple UserControl named "Marquee".
HTML
<usercontrol>
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="userControl"
	mc:Ignorable="d"
	xmlns:util="clr-namespace:CanvasClip"
	x:Class="Marquee.Marquee"
	d:DesignWidth="1125" d:DesignHeight="30">

	<grid x:name="LayoutRoot" xmlns:x="#unknown">
		<canvas x:name="MarqueeContainer" margin="0" util:clip.tobounds="true" xmlns:util="#unknown">
			<stackpanel x:name="MarqueeContent" d:layoutoverrides="VerticalMargin" orientation="Horizontal" canvas.left="0" height="30" loaded="MarqueeContent_Loaded" xmlns:d="#unknown" />
		</canvas>
	</grid>
</usercontrol>

In my MainPage I've inserted the user control "Marquee1" and set it's background property.
HTML
<grid x:name="LayoutRoot" xmlns:x="#unknown">
    <mrq:marquee x:name="Marquee1" height="30" verticalalignment="Top" margin="148,0,413,0" removed="#FFC8DC1A" xmlns:mrq="#unknown" />
    <Button Content="Button" Height="30" HorizontalAlignment="Left" Margin="393,134,0,0" x:Name="button1" VerticalAlignment="Top" Width="219" Click="button1_Click" />
</grid>

(Somehow I can't paste the code as it was on VS. Where it say "removed" it should be "background" on the mrq:Maquee element and the xmlns:mrq="#unknown" additions are strange to me.)

What I need is to bind the canvas "MarqueeContainer" background in the usercontrol "Marquee" to the "Marquee1" background property set on the MainPage.

In the usercontrol XAML It has to be something like:
Background="{Binding ???????}

But I'm kind of lost!
Posted
Updated 30-Oct-11 4:22am
v3

I have found a workaround in C# to be placed in the Loaded event of the usercontrol:
C#
MarqueeContainer.Background = ((Marquee)LayoutRoot.Parent).Background;


It works ... but I think that XAML would be the place to be.
 
Share this answer
 
You could use element to element binding.

Background = "{Binding Background, ElementName=LayoutRoot}"

LayouRoot being the grid of your application in this instance.
 
Share this answer
 
Allmost there Kelvin, thanks.

Got it working with:
HTML
Background="{Binding Background, ElementName=userControl}"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900