Skip to main content
Home Forums Silverlight Programming Programming with .NET - General custom control in Silverlight 1.1
13 replies. Latest Post by VladF on December 12, 2007.
(0)
zamzam
Member
12 points
12 Posts
11-13-2007 7:57 AM |
If you are creating a custom control in Silverlight 1.1 and shadowing properties (using the new keyword) that already exist on the Control class. If you set these properties in xaml nothing happens. But it works if set the properties in code.
Cass
Contributor
3157 points
654 Posts
11-13-2007 12:30 PM |
Can u give us an example? also the property code?
MarkTap
Participant
1442 points
263 Posts
11-13-2007 5:28 PM |
Do the parent versions of the properties get set from XAML? I.e. is it really "nothing" happening or is it just using the parent property setters?
11-14-2007 12:06 AM |
Here's what i am doing.
I created a class library using the Silverlight Class Library template in VS 2008 beta 2 and then I added a custom control (MyControl) using the template for Usercontrol.
Contents of MyControl.xaml.....
<
Width="200" Height="200" Background="Brown"></Canvas>
Contents of MyControl.xaml.cs......
using
{
System.IO.
}
Contents of Page.xaml.....
>
</
Contents of Page.xaml.cs.....
InitializeComponent();
control2.Height = 100;
control2.Width = 100;
Height and Width for 'control1' does not get affected but it works for 'control2'
11-14-2007 12:23 AM |
What are base.Width and base.Height for control1? I don't have time to try out your code right now, but it's probably using the parent Width and Height properties. I think you just need to set them in code for now - hopefully a subsequent release of Silverlight will have better integration of custom controls.
tanmoy.r
3594 points
710 Posts
11-14-2007 12:30 AM |
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
is it a typo? without quote?
balla
674 points
200 Posts
11-14-2007 3:35 AM |
I tried this and it really doesn't work! Putting a break-point into the set-properties that are created using the "new" keyword don't get called when initalizing through XAML. Whereas those without "new" are called properly when set using XAML. Using code-behind language to set the properties works fine for both. BUG (or feature)? PS: That's not a typo. This forum sometimes messes up links inserted into the Message.
Psychlis...
6045 points
973 Posts
11-14-2007 11:27 AM |
It's hard to say something is a bug when the whole thing is Alpha, but that's where I'd lean.
Since the control model is going to be overhauled, I would hope/expect this to change to however WPF would handle this situation.
Pete
i-mameir
38 points
13 Posts
11-14-2007 11:36 AM |
Hi!
it is not necessary to set the Width and Height Property! You get those values with "this.Width" and "this.Height"
if you try to overwrite these properties, it won't work!
Just don't code the properties "Width" and "Heigth" in your control, you will get the values anyway with "this.Height".
11-14-2007 11:48 AM |
i-mameir: Hi! it is not necessary to set the Width and Height Property! You get those values with "this.Width" and "this.Height" if you try to overwrite these properties, it won't work! Just don't code the properties "Width" and "Heigth" in your control, you will get the values anyway with "this.Height".
I know what he's trying to do, though, and it is a legit problem. When you set the width and height of the control, it doesn't change the root canvas width/height. You have to do that yourself. He was hoping (and it makes perfect sense) to encapsulate all that in an override of the Height/Width properties.
11-14-2007 12:33 PM |
yep i know ... but it seems not to work in alpha release :(
i hope they fix it soon though ...
philcurnow
54 points
11-15-2007 12:35 AM |
I came across the same problem when writing some custom controls. I had a search around on the net and found an entry on Jeff Prosise's blog about this. Aparently this is a bug in the Alpha release. I have put a link to his blog entry below.
Jeff Prosise's Blog Entry on this problem
Daliyot
2 points
1 Posts
12-11-2007 2:44 PM |
Has anyone else got it working directly from XAML without using the "new" keyword (like balla did)?
For me it didn't work with or without it.
VladF
216 points
87 Posts
12-12-2007 1:18 PM |
I use "shadow" string properties for my own properties which have custom type (enumeration for example):
DoHorizontalAlignmentChanged();
So I can set HorizontalAlignment_ in XAML and have correct value loaded into the HorizontalAlignment from XAML. This technique can also be used for Width/Height, but it will be useless if you use some tool for XAML editing.