Skip to main content
Home Forums Other Feedback on this Website Need a Suggestion Topic
7 replies. Latest Post by K2P2 on August 6, 2008.
(0)
K2P2
Participant
1028 points
337 Posts
08-06-2008 12:51 PM |
This site is great - thanks a lot.
One thing I would like is a Suggestion Topic.
Currently I can go to the SILVERLIGHT PROGRAMMING forum and "Report a Silverlight Bug" or ask questions in many places but there is nowhere to make a suggestion. Suggestions don't really fit under "what do you think about this site" either.
I can over load the Bug reporting system - but because I don't really want to ask a question or I just sit on my idea or "complaint".
Example:
I have some xaml that doesn't provide Width and Height:
<
This xaml displays my control fine but when I subscribe to the loaded event the Width and Height are set to NaN. This of course is ridiculous because my "large" control is displaying fine. I would like to do some things with the Width and Height which "must" be known. This may not be a bug but designed in for some reason....
Thanks,Kevin
johnnystock
Contributor
2295 points
362 Posts
08-06-2008 1:01 PM |
I agree on the need for a suggestion forum.
For your particular situation though, have you tried ActualHeight and ActualWidth? I'm not sure if those are available on UserControl but they are usually what you use at runtime to determine height and width.
08-06-2008 2:17 PM |
Thanks for the reply,
No big stessor. I just put the width and height into my xaml.
None-the-less I took them out for a second and tried ActualWidth and ActualHeight. They showed up as 0.0, which is better than NaN.
I haven't thought about it but maybe 0.0 / Nan would work. :)
Keith.Ma...
872 points
131 Posts
08-06-2008 2:30 PM |
The values of Width and Height are never set by the silverlight runtime, they are user set properties and will only ever have the values of what they are set to (or the default of NaN). A value of NaN is considered to be "Auto" sizing.
ActualWidth and ActualHeight are read only properties which are set by the runtime. They are set by the layout system which usually runs in an asynchronous manner. If you want to determine the size of a UserControl, handle the SizeChanged event and examine the ActualWidth/ActualHeight properties. Alternatively, you can force a synchronous layout pass by calling UpdateLayout() on the UserControl, and then examining the ActualWidth/ActualHeight properties.
08-06-2008 3:13 PM |
Nice try but no cigar.
For your benefit I put a SizeChanged event on my UserControl and on a child Canvas (I didn't look at the size of the Canvas because I am not interested in it). Also, for your benefit, I called UpdateLayout() from "everywhere" without success.
As a matter of fact the SizeChanged event, in this case, is never fired. And it shouldn't. Because the size never changes.
Here's the code. I am not really concerned about this and I have other things to do. If you think it is a bug I will enter it in the system. Otherwise I am not going to spend any more time on this.
Thanks alot for your interest.
Kevin
namespace Site1{ public partial class StartPage : UserControl { public StartPage () { InitializeComponent ();
PrevButton.Click += new RoutedEventHandler ( PrevButtonHandler ); NextButton.Click += new RoutedEventHandler ( NextButtonHandler ); UpdateLayout (); }
void PrevButtonHandler ( object sender, RoutedEventArgs e ) { UpdateLayout (); } void NextButtonHandler ( object sender, RoutedEventArgs e ) { UpdateLayout (); }
private void ParentCanvas_Loaded ( object sender, RoutedEventArgs e ) { UpdateLayout (); }
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) { double w = ActualWidth; double h = ActualHeight; }
private void ParentCanvas_SizeChanged(object sender, SizeChangedEventArgs e) { double w = ActualWidth; double h = ActualHeight; }
}}
<UserControl x:Class="Site1.StartPage" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" SizeChanged="UserControl_SizeChanged" > <Canvas x:Name="ParentCanvas" Background="LightBlue" Loaded="ParentCanvas_Loaded" SizeChanged="ParentCanvas_SizeChanged" > <StackPanel Background="LightBlue" > <Canvas Background="Blue" Width="700" Height="400" > <Canvas Background="DarkMagenta" Width="680" Height="382" Margin="10,9,0,0" > </Canvas> </Canvas> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,5" > <Button x:Name="PrevButton" Content="Prev" Width="100" Height="20" HorizontalAlignment="Left"></Button> <Button x:Name="NextButton" Content="Next" Margin="5,0,0,0" Width="100" Height="20" HorizontalAlignment="Left"></Button> </StackPanel> </StackPanel> </Canvas></UserControl>
08-06-2008 3:30 PM |
I put a break point in my "PrevButtonHandler" and the Width, Height, ActualWidth and ActualHeight show up fine.
I guess what I could do is start a timer or something during the loaded event and then when the timer triggers get my Width and Height.
There are probably a thousand ways to do this. But it seems to me that these should be available at the Loaded event.
08-06-2008 3:35 PM |
As a matter of fact I put in a handler to the LayoutUpdated event and after two or three calls all of these properties are fine.
08-06-2008 5:25 PM |
Sorry, this is so much noise. But I don't want to lead some future reader astray.
This may not work afterall. I have been doing some other work and may have left the Width and Height properties set in the xaml. So that may be why they came through on the LayoutUpdated event.
Again, this is of little interest to me. So please do not try to validate this or that on my account.
Again, Sorry.