2017-02-28 25 views

回答

2

注意,視框縮放其內容的呈現的輸出(包括例如PathStrokeThickness),但不是圖的幾何形狀。

以下方法工作,而不縮放StrokeThickness,因爲Ellipse控制縮放其幾何形狀以適應其邊界:

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition/> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 
    <Border ClipToBounds="True"> 
     <Ellipse Stroke="Black" StrokeThickness="1" RenderTransformOrigin="0,1"> 
      <Ellipse.RenderTransform> 
       <ScaleTransform ScaleX="2" ScaleY="2"/> 
      </Ellipse.RenderTransform> 
     </Ellipse> 
    </Border> 
</Grid> 
+0

我觀察到筆畫粗細的縮放。在一個WPF應用程序中,這個解決方案很不幸,當在一個UWP項目中使用相同的代碼時,邊界沒有ClipToBounds屬性,我所看到的對於模仿一條線而不是一半橢圓是至關重要的。 –

+0

你已經用WPF標記了你的問題。無論如何,看到這裏:http://stackoverflow.com/q/13668236/1136211 – Clemens

+0

我的錯誤,已標記爲更理想的答案 –

2

兩者都具有1 *

的寬度要在第一列網格創建在窗口與2列的網格添加一個視框與StretchDirection =兩個和拉伸=填寫

在視圖框內添加曲線。

當窗口調整大小時,列將變小,並且視圖框將向下翻轉內容。

<Window x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication1" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="1*"/> 
     <ColumnDefinition Width="1*"/> 
    </Grid.ColumnDefinitions> 
    <Viewbox StretchDirection="Both" Stretch="Fill"> 
     <Canvas Width="100" Height="200"> 
      <Path Stroke="Black" StrokeThickness="3"> 
       <Path.Data> 
        <PathGeometry> 
         <PathGeometry.Figures> 
          <PathFigure StartPoint="0,0" IsClosed="False"> 
           <ArcSegment Point="100,100" Size="100 100"/> 
          </PathFigure> 
         </PathGeometry.Figures> 
        </PathGeometry> 
       </Path.Data> 
      </Path> 
     </Canvas> 
    </Viewbox> 
</Grid>