2017-02-10 60 views
0

我創建了我自己的UserControl(自定義加載動畫) 當我將我的usercontrol放到頁面時,我想縮放我的usercontrol內部的所有組件。用戶控件包含橢圓,矩形和雙動畫邏輯。UserControl縮放Windows Phone 8.1

<UserControl 
x:Class="UC_test" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:WP_Eq_App" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="200" 
d:DesignWidth="200"> 

<Grid x:Name="mainGrid"> 
    <Grid.RowDefinitions> 

     <RowDefinition Height="Auto" /> 
     <!--<<< Will resize to the size of contents --> 

    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="Auto"/> 

    </Grid.ColumnDefinitions> 

    <Ellipse x:Name="MainEl" RenderTransformOrigin=".5,.5" Fill="Transparent" HorizontalAlignment="Left" Height="150" StrokeThickness="5" Stroke="Black" VerticalAlignment="Top" Width="150" Margin="0,0,0,0"/> 


</Grid> 
</UserControl> 

請幫助我這個簡單的例子。 謝謝。

回答

1

如果您希望內容自動縮放,您應該將它放在ViewBox控件中。

<UserControl 
x:Class="UC_test" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:WP_Eq_App" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="200" 
d:DesignWidth="200"> 
    <ViewBox> 
     <Ellipse x:Name="MainEl" RenderTransformOrigin=".5,.5" Fill="Transparent" HorizontalAlignment="Left" Height="150" StrokeThickness="5" Stroke="Black" VerticalAlignment="Top" Width="150" Margin="0,0,0,0"/> 
    </ViewBox> 
</UserControl> 

ViewBox控制可以有1個小孩,所以如果你希望把更多的控制,將它們包裝在GridStackPanel

+0

太棒了!很有幫助! – cybergogic