2016-06-12 34 views
0

Wie Sie die Bindungen arbeiten lassen, so dass ich während der Designzeit die drei Positionen neu berechnen kann, die ich brauche, um den Pfad zu rendern. Wann ändert jemand die Größe des customcontrol?WPF usercontrol circlesector Taste

Jetzt habe ich gerade versucht, eine Verbindung mit dem Sizechanged-Ereignis ..

<Grid DataContext="{Binding ElementName=mainbutton}"> 
    <Path Stroke="{Binding Path=BorderBrush}" StrokeThickness="1" Fill="{Binding Path=Foreground}"> 
     <Path.Data> 
      <PathGeometry> 
       <PathGeometry.Figures> 
        <PathFigureCollection> 
         <PathFigure IsClosed="True" StartPoint="{Binding Path= CenterPoint}"> 
          <PathFigure.Segments> 
           <PathSegmentCollection> 
            <!--<Path Stroke="Black" StrokeThickness="1" Data="M 180,180 L 271.9,88.1 A130,130 0 0 0 88.1,88.1 Z"/>--> 
            <LineSegment Point="{Binding Path= TopLeftPoint}"/> 
            <ArcSegment Point="{Binding Path= TopRightPoint}" Size="{Binding Path= Size}" IsLargeArc="False" SweepDirection="Clockwise" RotationAngle="0"/> 
           </PathSegmentCollection> 
          </PathFigure.Segments> 
         </PathFigure> 
        </PathFigureCollection> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 
</Grid> 

Antwort

0

gut u könnte eine „Eigenschaft geändert Trigger“ hinzufügen und auf das geänderte Ereignis Größe befestigen, und legen Sie dann die Objekte horizontal \ vertikale Anpassungseigenschaften.

here's an example

0

ich eine Lösung für dieses Problem gefunden.

XAML-Datei:

 <Path Stroke="CornflowerBlue" StrokeThickness="5" StrokeStartLineCap="Round" StrokeEndLineCap="Round"> 
     <Path.Data> 
      <PathGeometry> 
       <PathFigure StartPoint="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ArcProgress}},Path=StartPoint, Mode=OneWay}"> 
        <ArcSegment Point="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ArcProgress}},Path=EndPoint, Mode=OneWay}" 
           Size="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ArcProgress}},Path=CircleSize, Mode=OneWay}" SweepDirection="Clockwise" /> 
       </PathFigure> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 

und für die cs-Datei.

public partial class ArcProgress : System.Windows.Controls.UserControl 
{ 
    public static readonly DependencyProperty ProgressProperty = 
     DependencyProperty.Register("Progress", typeof(double), typeof(ArcProgress), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender,(o, e) => { ((ArcProgress)o).UpdateGeometry(); })); 

    static ArcProgress() 
    { 
     WidthProperty.OverrideMetadata(typeof(ArcProgress), new FrameworkPropertyMetadata((o, e) => { ((ArcProgress)o).UpdateGeometry(); })); 
     HeightProperty.OverrideMetadata(typeof(ArcProgress), new FrameworkPropertyMetadata((o, e) => { ((ArcProgress)o).UpdateGeometry(); })); 

    }  

    private void UpdateGeometry() 
    { 
     if (!double.IsNaN(Width) && !double.IsNaN(Height)) 
     { 

      double x = (Progress/100.0) * Width; 
      double y = (Progress/100.0) * Height; 
      StartPoint = new Point(x, 0); 
      EndPoint = new Point(0, y); 
      CircleSize = new Size(x, y); 
     } 
    } 

Dieses Snippet stammt aus einer anderen Komponente.