Я создал новую панель с именем LinearLayout, и у меня возникли проблемы с управлением раскладкой, потому что поле selectedSize не устанавливается после вызова метода MeasureOverride ... вот мой код:
protected override Size MeasureOverride(Size availableSize)
{
Size panelDesiredSize = new Size();
if ((this.widthWrap) || (this.heightWrap))
{
foreach (UIElement elemento in this.Children)
{
System.Diagnostics.Debug.WriteLine("Measure" + ((FrameworkElement)elemento).Name);
((FrameworkElement)elemento).Measure(new Size(((FrameworkElement)elemento).Width, ((FrameworkElement)elemento).Height));
System.Diagnostics.Debug.WriteLine(" child this desireddSIze" + ((FrameworkElement)elemento).DesiredSize);
if (this.Orientation.Equals(System.Windows.Controls.Orientation.Vertical))
{
if (this.widthWrap)
{
//the widest element will determine containers width
if (panelDesiredSize.Width < ((FrameworkElement)elemento).Width)
panelDesiredSize.Width = ((FrameworkElement)elemento).Width;
}
//the height of the Layout is determine by the sum of all the elment that it cointains
if (this.heightWrap)
panelDesiredSize.Height += ((FrameworkElement)elemento).Height;
}
else
{
if (this.heightWrap)
{
//The highest will determine the height of the Layout
if (panelDesiredSize.Height < ((FrameworkElement)elemento).Height)
panelDesiredSize.Height = ((FrameworkElement)elemento).Height;
}
//The width of the container is the sum of all the elements widths
if (this.widthWrap)
panelDesiredSize.Width += ((FrameworkElement)elemento).DesiredSize.Width;
}
}
}
return panelDesiredSize;
}
Я вкладываю два линейных макета: L1 является родителем L2, а L2 является родителем 3 кнопок.
И забавно то, что если я напишу приведенный ниже код в любом месте класса LinearLayout, он будет работать, и механизм Layout вызывается снова, и он работает нормально ... но если я вызываю UpdateLayout (), ничего не происходит, и механизм не активирован (measureoverride иrangeoverride не называются)
this.Width = finalSize.Width;
this.Height = finalSize.Height;
Это ошибка? или это только у меня ??? Я был уже два дня, и, кажется, работает для остальных людей ...
Если кто-нибудь может мне помочь, я буду очень признателен!
Кстати, я работаю с Silverlight для Windows Phone 7 ...