Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Shelf : Panel
- {
- public static readonly DependencyProperty ExactProperty = DependencyProperty.RegisterAttached("Exact", typeof(int), typeof(Shelf),
- new FrameworkPropertyMetadata(100, new PropertyChangedCallback(OnExactChanged)));
- private static void OnExactChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- Console.WriteLine(d); // This Callback is added only for debug purposes
- }
- public static int GetExact(UIElement element)
- {
- return (int)element.GetValue(ExactProperty);
- }
- public static void SetExact(UIElement element, int value)
- {
- element.SetValue(ExactProperty, value);
- }
- protected override Size MeasureOverride(Size availableSize)
- {
- Size panelSize = new Size(availableSize.Width, 0);
- foreach (UIElement child in InternalChildren)
- {
- child.Measure(availableSize);
- panelSize.Height += child.DesiredSize.Height;
- }
- return panelSize;
- }
- protected override Size ArrangeOverride(Size finalSize)
- {
- foreach (UIElement child in InternalChildren)
- {
- int exact = Shelf.GetExact(child); // Here I always get 100 which is default value for ExactProperty
- child.Arrange(new Rect(new Point(0, exact * 1), child.DesiredSize));
- }
- return finalSize;
- }
- }
- <ItemsControl ItemsSource="{Binding Path=Packs}">
- <ItemsControl.ItemsPanel>
- <ItemsPanelTemplate>
- <local:Shelf />
- </ItemsPanelTemplate>
- </ItemsControl.ItemsPanel>
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <TextBlock local:Shelf.Exact="{Binding Path=Number}" Text="{Binding Path=Name}"/>
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>
- <local:Shelf Grid.Column="1">
- <TextBlock local:Shelf.Exact="223">Test</TextBlock>
- <TextBlock local:Shelf.Exact="332">Test</TextBlock>
- <TextBlock local:Shelf.Exact="443">Test</TextBlock>
- </local:Shelf>
- <ItemsControl ItemsSource="{Binding Packs}">
- <ItemsControl.ItemsPanel>
- <ItemsPanelTemplate>
- <local:Shelf/>
- </ItemsPanelTemplate>
- </ItemsControl.ItemsPanel>
- <ItemsControl.ItemContainerStyle>
- <Style TargetType="ContentPresenter">
- <Setter Property="local:Shelf.Exact" Value="{Binding Number}"/>
- </Style>
- </ItemsControl.ItemContainerStyle>
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Name}"/>
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>
Add Comment
Please, Sign In to add comment