2014-08-27 43 views
0

我有有這樣綁定的高度和邊框的寬度,以它的一半兒

<UserControl 
x:Class="App2.MyImageControl" 
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" 
d:DesignHeight="300" 
d:DesignWidth="400"> 

<Grid x:Name="MyGrid" x:FieldModifier="public" ManipulationMode="None" Tapped="MyGrid_Tapped" HorizontalAlignment="Left" VerticalAlignment="Top" > 
    <Grid.RenderTransform> 
     <CompositeTransform></CompositeTransform> 
    </Grid.RenderTransform> 
    <Border x:Name="MyBorder" x:FieldModifier="public" BorderThickness="1" BorderBrush="Transparent" Width="auto" Height="auto"> 
     <Grid> 
      <Image x:Name="MyImageO" x:FieldModifier="public" Source="" Width="auto" Height="auto" Stretch="Fill"></Image> 

     </Grid> 

    </Border> 
</Grid> 

我想MyBorder寬度和高度綁定到元素的用戶控件MyImageO寬度和高度在運行時的一半。我該如何實現這一點。

回答

1

您可以嘗試使用MultiplyConverter將綁定值轉換爲其中的一半,但ActualWidthActualHeight不可綁定 - 它們不引發更改通知。最好的辦法是簡單地處理SizeChanged事件,然後根據圖像的ActualWidthActualHeight設置邊框的尺寸。