请问在WPF中,怎样在VisualBrush中的到引用它的元素的ActualWidth和ActualHeight?
yezzi 2009-03-26 05:20:37 比如下面的代码:
[code=XAML]
<Page x:Class="wpf.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="431">
<Page.Resources>
<VisualBrush x:Key="BrushStyle1">
<VisualBrush.Visual>
<Border Background="blue" BorderBrush="red" Width="???????????" Height="???????????" BorderThickness="1"/>
</VisualBrush.Visual>
</VisualBrush>
</Page.Resources>
<Grid>
<Button Width="50" Height="50" Name="button1" VerticalAlignment="Top" Background="{StaticResource BrushStyle1}">Button</Button>
<Border Width="200" Height="200" Name="border1" Background="{StaticResource BrushStyle1}"/>
</Grid>
</Page>
[/code]
问号里面该怎么填,才能得到引用它的Button或Border的ActualWidth和ActualHeight呢?
我有实验过下面这个方法,但是没用。。。。好烦。。。。
[code=XAML]
Width="{Binding Path=ActualWidth,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Border},AncestorLevel=1}}"
[/code]
望高手指教!