Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. How do you use MeasureOverride in Silverlight?
  2. protected override Size MeasureOverride(Size availableSize) {
  3.  
  4. Size panelDesiredSize = new Size();
  5.  
  6.  
  7. if ((this.widthWrap) || (this.heightWrap))
  8. {
  9.  
  10. foreach (UIElement elemento in this.Children)
  11. {
  12.  
  13. System.Diagnostics.Debug.WriteLine(((FrameworkElement)elemento).DesiredSize.ToString());
  14.  
  15. if (this.Orientation.Equals(System.Windows.Controls.Orientation.Vertical))
  16. {
  17. if (this.widthWrap)
  18. {
  19. //the widest element will determine containers width
  20. if (panelDesiredSize.Width < ((FrameworkElement)elemento).Width)
  21. panelDesiredSize.Width = ((FrameworkElement)elemento).Width;
  22. }
  23. //the height of the Layout is determine by the sum of all the elment that it cointains
  24. if (this.heightWrap)
  25. panelDesiredSize.Height += ((FrameworkElement)elemento).Height;
  26. }
  27. else
  28. {
  29. if (this.heightWrap)
  30. {
  31. //The highest will determine the height of the Layout
  32. if (panelDesiredSize.Height < ((FrameworkElement)elemento).Height)
  33. panelDesiredSize.Height = ((FrameworkElement)elemento).Height;
  34. }
  35.  
  36. //The width of the container is the sum of all the elements widths
  37. if (this.widthWrap)
  38. panelDesiredSize.Width += ((FrameworkElement)elemento).Width;
  39. }
  40.  
  41. }
  42. }
  43.  
  44. System.Diagnostics.Debug.WriteLine("desiredsizzeeeeeee" + panelDesiredSize);
  45.  
  46. return panelDesiredSize;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement