Draw a circle in WPF using min(width, height)/2 as radius

后端 未结 2 1656
故里飘歌
故里飘歌 2021-02-20 09:26

How I can draw a circle in WPF (without code-behind) using min(width, height)/2 as radius?

相关标签:
2条回答
  • 2021-02-20 09:46

    you can do it in pure XAML you just need to use Binding for the values. You also have to make sure that everything is named

      <Grid Name="grdMain"> 
          <Grid.ColumnDefinitions>
             <ColumnDefinition Width="75" Name="Col1" />
             <ColumnDefinition Width="100" Name="Col2" />
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
              <RowDefinition Height="75" Name="Row1" />
                    <RowDefinition Height="100" Name="Row2" />
          </Grid.RowDefinitions>
    
               <Ellipse Grid.Column="1" Grid.Row="1"
                    Canvas.Top="50"
                    Canvas.Left="50"
                    Fill="#FFFFFF00"
                    Height="{Binding RowDefinitions/ActualHeight, ElementName=Row1, Mode=OneWay}"
                    Width="{Binding ColumnDefinitions/ActualWidth, ElementName=Col1, Mode=OneWay}"
                    StrokeThickness="5"
                    Stroke="#FF0000FF"/>
       </Grid>
    
    0 讨论(0)
  • 2021-02-20 09:56

    Where does width and height come from? Example XAML for a circle is:

       <Canvas Background="LightGray"> 
           <Ellipse
              Canvas.Top="50"
              Canvas.Left="50"
              Fill="#FFFFFF00"
              Height="75"
              Width="75"
              StrokeThickness="5"
              Stroke="#FF0000FF"/>
        </Canvas>
    

    A circle is just an Ellipse where Height = Width.

    0 讨论(0)
提交回复
热议问题