カスタム パネルに対して次のように宣言された添付プロパティがあります。
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);
}
パネルを次のように定義すると、正常に動作します。
<local:WeightedPanel Grid.Row="0" Height="200">
<Button local:WeightedPanel.Weight="8" />
<Button local:WeightedPanel.Weight="2"/>
</local:WeightedPanel>
しかし、このパネルを として使用ItemsPanelTemplate
するListBox
と、常にデフォルト値が に返されますArrangeOverride
。
<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>
また、カスタム ラップ パネルを で使用すると、Arrange メソッドListBox
が送信されるため、Arrange で値を設定できないことにも気付きました。double.PositiveInfinite
単独で使用しても同じように機能します
ありがとう