.net 从ViewBox拉伸中豁免AdornerLayer中的控件
我有一个WPF控件,大致布局如下:.net 从ViewBox拉伸中豁免AdornerLayer中的控件,.net,wpf,c#-4.0,.net,Wpf,C# 4.0,我有一个WPF控件,大致布局如下: <ViewBox Stretch="Uniform" Name="viewboxName"> <ItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <!-- a bunch of controls here that I want stretched in the v
<ViewBox Stretch="Uniform" Name="viewboxName">
<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- a bunch of controls here that I want stretched in the viewbox -->
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ViewBox>
然后,在AdornerLayer中,我(使用基于的技术)有一个按钮控件,定义为
<Button>
<Image Source="/AcchImageLoad;component/icons/metroStudio/ImageRotation.png" Stretch="None" />
</Button>
如何让AdornerLayer中的此按钮使用图像的本机分辨率,而不是使用ViewBox进行拉伸?基本上,想法是从
ViewBox
获取变换,并使用绑定转换器应用反转
绑定转换器可以使用以下代码获得相反的结果:
((ContainerVisual)VisualTreeHelper
.GetChild((System.Windows.DependencyObject)viewbox, 0)).Transform.Inverse
在xaml中,绑定看起来像
<Button.LayoutTransform>
<MultiBinding Converter="{bc:ExemptFromViewboxTransformConverter}">
<Binding Source="{x:Reference Name=viewboxName}" />
<!-- The ActualWidth/ActualHeight bindings are only used to ensure
the transform updates when the window is resized. -->
<Binding Source="{x:Reference Name=viewboxName}" Path="ActualWidth" />
<Binding Source="{x:Reference Name=viewboxName}" Path="ActualHeight" />
</MultiBinding>
</Button.LayoutTransform>
另见:
视图框
中获取变换,并使用绑定转换器应用逆运算
绑定转换器可以使用以下代码获得相反的结果:
((ContainerVisual)VisualTreeHelper
.GetChild((System.Windows.DependencyObject)viewbox, 0)).Transform.Inverse
在xaml中,绑定看起来像
<Button.LayoutTransform>
<MultiBinding Converter="{bc:ExemptFromViewboxTransformConverter}">
<Binding Source="{x:Reference Name=viewboxName}" />
<!-- The ActualWidth/ActualHeight bindings are only used to ensure
the transform updates when the window is resized. -->
<Binding Source="{x:Reference Name=viewboxName}" Path="ActualWidth" />
<Binding Source="{x:Reference Name=viewboxName}" Path="ActualHeight" />
</MultiBinding>
</Button.LayoutTransform>
另见:
您可以使用此解决方案禁用viewbox缩放: 基本上,为ViewBox_SizeChanged添加一个处理程序,并将豁免元素的变换设置为ViewBox变换的倒数 然后在XAML中,添加ViewBoxExtra.DisableScaling=“true”,例如