Xaml 在windows 8.1应用程序中,运行时将边框的高度和宽度绑定到其一半子级
我有一个用户控件,它有如下元素Xaml 在windows 8.1应用程序中,运行时将边框的高度和宽度绑定到其一半子级,xaml,windows-store-apps,windows-8.1,Xaml,Windows Store Apps,Windows 8.1,我有一个用户控件,它有如下元素 <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/expr
<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>
我想在运行时将我的边框宽度和高度绑定到MyImageO宽度和高度的一半。我该如何实现这一点 您可以尝试使用将绑定值转换为它的一半,但是实际宽度
和实际高度
不可绑定-它们不会引发更改通知。最好的方法是简单地处理SizeChanged
事件,然后根据图像的ActualWidth
和ActualHeight
设置边框的尺寸