Scale items with ViewBox within an ItemsControl
-
So I have some FrameworkElements that I want to scale with a ViewBox. This works fine with normal XAML code:
But as soon as I want to join them together and scale them appropriately to the available size I have a problem:
The ViewBox simply refuses to scale them according to the set size of the ViewBox. Any ideas on how to fix this?
-
So I have some FrameworkElements that I want to scale with a ViewBox. This works fine with normal XAML code:
But as soon as I want to join them together and scale them appropriately to the available size I have a problem:
The ViewBox simply refuses to scale them according to the set size of the ViewBox. Any ideas on how to fix this?
Still havent found out what was wrong with this, but here is one of the FrameworkElements Im trying to bind the ItemsControl to
public class SourceDiagramBase : FrameworkElement, INotifyPropertyChanged { private VisualCollection \_children; public SourceDiagramBase() { \_children = new VisualCollection(this); \_children.Add(CreateDrawingVisual()); } protected override int VisualChildrenCount { get { return \_children.Count; } } protected override Visual GetVisualChild(int index) { return \_children\[index\]; } public double Scale { get { return (double)GetValue(ScaleProperty); } set { SetValue(ScaleProperty, value); } } // Using a DependencyProperty as the backing store for Scale. This enables animation, styling, binding, etc... public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(SourceDiagramBase), new PropertyMetadata(20d)); protected override Size MeasureOverride(Size availableSize) { return new Size(this.Scale \* 12d, this.Scale \* 12d); } private DrawingVisual CreateDrawingVisual() { DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.PushTransform(new ScaleTransform(this.Scale, this.Scale)); double thick = 0.04; drawingContext.DrawEllipse(Brushes.Transparent, new Pen(Brushes.Black, thick), new Point(6, 6), 3,3); drawingContext.DrawLine(new Pen(Brushes.Black, thick), new Point(6, 3), new Point(6, 2)); drawingContext.DrawLine(new Pen(Brushes.Black, thick), new Point(6, 9), new Point(6, 10)); drawingContext.DrawLine(new Pen(Brushes.Black, thick), new Point(6, 2), new Point(12, 2)); drawingContext.DrawLine(new Pen(Brushes.Black, thick), new Point(6, 10), new Point(12, 10)); drawingContext.Close(); return drawingVisual; } public event PropertyChangedEventHandler PropertyChanged; // This method is called by the Set accessor of each property. // The CallerMemberName attribute that is applied to the optional propertyName // parameter causes the property name of the caller to be substituted as