2016-05-17 50 views
0

「width = 'auto'」の楕円形があり、円が必要なため、「height = 'auto'」は設定できません。ウィンドウは、円は楕円になります。私は "Height = '{バインディングElementName = TheLeft、Path =幅}'を試みました。"動的要素の値を別の要素に割り当てる

<Page 
    x:Class="App2.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:App2" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="White"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="3*" /> 
      <ColumnDefinition Width="1*" /> 
      <ColumnDefinition Width="3*" /> 
     </Grid.ColumnDefinitions> 
     <!--<Ellipse x:Name="TheLeft" Fill="Pink" Grid.Column="0" Height="{Binding ElementName=TheLeft, Path=Width}" Width="auto" VerticalAlignment="Bottom"/>--> 
     <!-- I've set Height="200" in the uncommented element --> 
     <Ellipse x:Name="TheLeft" Fill="Pink" Grid.Column="0" Height="200" Width="auto" VerticalAlignment="Bottom"/> 

     <Rectangle Fill="Red" Grid.Column="1" RadiusX="50" RadiusY="40"/> 
     <Ellipse Fill="Pink" Grid.Column="2" Height="200" Width="auto" VerticalAlignment="Bottom"/> 
    </Grid> 
</Page> 

答えて

0

まず、私は間違いなくあなたが2つの楕円のプロパティの多くは同じ値にしたい、特に以来、あなたはインラインスタイリングを取る提案するつもりです。その後、

<Style x:Key="circularEllipse" TargetType="{x:Type Ellipse"}> 
    <Setter Property="Fill" Value="Pink"/> 
    <Setter Property="VerticalAlignment" Value="Bottom"/> 
    <Setter Property="Height" Value="200"/> 
    <Setter Property="Width" Value="{Binding Path=Height, RelativeSource={RelativeSource Self}}"/> 
</Style> 

そして、あなたは楕円をコーディング - あなただけのこのスタイルを呼び出す必要があり、それはあなたが時間をコーディングして、レイアウト上のコードの量を減らす節約、それらの両方に使用することができます。

円のサイズを変更する必要がある場合は、プロパティを1か所で変更するだけで済みます。また、バリアントが必要な場合は、BasedOnオプションを使用して、コード全体をやり直す必要はありません。以下のような:

<Style x:Key="circularEllipse2" TargetType="{x:Type Ellipse}" BasedOn="{StaticResource circularEllipse}"> 
    <Setter Property="Height" Value="100"/> 
</Style> 

これは、以前のスタイルから他のすべてのプロパティを拾うが、高さ(または変更する必要があるかもしれない他のプロパティ)を変更

ます
関連する問題