Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Silverlight 2: Canvas visibility change not applied until user moves mouse over controls
9 replies. Latest Post by jjy2 on March 11, 2008.
(0)
AdamJTP
Member
36 points
12 Posts
03-07-2008 7:59 AM |
Symptom:
A canvas has visibility changed from Visibilty.Collapsed to Visibilty.Visible but controls inside the canvas don't appear until mouse hovers over them.
Steps to repro:
1. Create a Silverlight 2 app
2. Change the Page XAML to look like this (either manually or in Blend)
<
</
3. Change the Visibility of cnvTest on clicking the button
{
InitializeComponent();
}
Expected the button in the canvas to be shown as soon as the canvas is made visible.
Dave Relyea
Participant
1084 points
249 Posts
03-09-2008 11:59 AM |
Yup. Looks like a bug in Button. (If the second Button is a TextBlock, it appears right away.)
Thanks for reporting this.
03-09-2008 6:36 PM |
Thanks. I guess that's answered.
03-10-2008 8:38 AM |
Further investigation shows it's anything derived from control.
UserControls, Buttons, Textboxes none of them work.
You're right about TextBlock working.
I think that this is pretty serious.
03-10-2008 9:31 AM |
The workarounds we've found:
1. Set the initial visibility of the canvas to hide to Visible - set the visibility to Collapsed in the first SizeChanged event
2. Explicitly set the Visibility of the control in the canvas to Visible (even though it already is visible)
3. Use Grid or StackPanel as the container (these both work)
03-10-2008 10:21 AM |
Thanks for drilling in further. We'll definitely take a look.
jjy2
354 points
155 Posts
03-10-2008 11:32 PM |
I'd like to add one comment on this.
I have problem with Canvas object that doesn’t fire SizeChanged event when I change it’s Width or Height, however when I mouse over a button, then it suddenly fires SizeChanged event. This makes my custom layout very difficult at this time.
This seems to happen when I have nested Canvas objects with StackPanel or Grid, though I couldn’t find out the pattern of this problem yet. Still doing some testing on this
(It's may not be the same problem but I just thought problem may be in Cavas (or layout system) rather than the button)
03-11-2008 9:49 AM |
Hi Davd Relyea again,
Like you suggested in another post, I am porting my code to use two-pass layout system by deriving Panel class, or try to use default layout containers as much as I can. However I still need many portion of my code using Canvas as they rely on x-y coordinates and items are depending on the size of Canvas (perhabs I should inherit Canvas and use OverrideArrange to see what size is coming along?). I am just trying to mix all layout methods I can.
Problem 1: I was testing Canvas objects again and again and realized that Canvas itself doesn’t appear if it contains any layout elements in it. Very much similar to AdamJTP’s problem
Problem 2: When I have nested SizeChange events as I have nested Canvases. It only seem to fire SizeChanged event for first few Canvases. May be I am doing something wrong here, your advice would be greatly appriciated.I just wish to make my application up and running again soon. Below is my test program
Thanks a lot for your help
App.xaml.cs
this.root = new Page(); this.RootVisual = this.root; }
03-11-2008 10:01 AM |
Sorry for the mess, it lost all format. I manually formatted code again. thanks
03-11-2008 10:34 AM |
Just one more thing, when layout elements are displayed try to move mouse over the button. Then suddenly SizeChanged event fires