I have an Attached property declared for my custom panel as
public static readonly DependencyProperty WeightProperty = DependencyProperty.RegisterAttached(
"Weight", typeof(double), typeof(WeightedPanel),
new FrameworkPropertyMetadata(1.0,
FrameworkPropertyMetadataOptions.AffectsParentMeasure |
FrameworkPropertyMetadataOptions.AffectsParentArrange ));
public static void SetWeight(DependencyObject obj, double weight)
{
obj.SetValue(WeightProperty, weight);
}
public static double GetWeight(DependencyObject obj)
{
return (double) obj.GetValue(WeightProperty);
}
it works fine if I define the panel as
<local:WeightedPanel Grid.Row="0" Height="200">
<Button local:WeightedPanel.Weight="8" />
<Button local:WeightedPanel.Weight="2"/>
</local:WeightedPanel>
But if I use this panel as ItemsPanelTemplate for a listbox, it always returns the default value in ArrangeOverrdie
<ListBox Grid.Row="2" Height="100">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<local:WeightedPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<Button local:WeightedPanel.Weight ="6" />
<Button local:WeightedPanel.Weight ="4"/>
</ListBox>
I also noticed that when the custom wrap panel is used in a listbox, it sends double.PositiveInfinite in Arrange method and therefore Arrange is never able to set the values. The same works fine when used all by itself
Thanks