Skip to main content

Microsoft Silverlight

Unanswered Question Need a Suggestion TopicRSS Feed

(0)

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Need a Suggestion Topic

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:

<UserControl x:Class="Site1.StartPage"
xmlns=http://schemas.microsoft.com/client/2007
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
>

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
johnnystock

Contributor

Contributor

2295 points

362 Posts

Silverlight MVP

Re: Need a Suggestion Topic

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.

John Stockton
Microsoft Silverlight MVP and RIA Developer at Ascentium
Co-Author of Silverlight 2 in Action

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Need a Suggestion Topic

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.Mahoney
Keith.Ma...

Participant

Participant

872 points

131 Posts

Microsoft

Re: Need a Suggestion Topic

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.

Keith Mahoney
Silverlight SDET
Microsoft

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Need a Suggestion Topic

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>

 

 

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Need a Suggestion Topic

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.

Kevin

 

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Need a Suggestion Topic

 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.

Thanks,
Kevin

K2P2
K2P2

Participant

Participant

1028 points

337 Posts

Re: Need a Suggestion Topic

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.

Kevin

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities