Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从ViewBox拉伸中豁免AdornerLayer中的控件_.net_Wpf_C# 4.0 - Fatal编程技术网

.net 从ViewBox拉伸中豁免AdornerLayer中的控件

.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

我有一个WPF控件,大致布局如下:

<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”,例如


您可以使用此解决方案禁用viewbox缩放:

基本上,为ViewBox_SizeChanged添加一个处理程序,并将豁免元素的变换设置为ViewBox变换的倒数

然后在XAML中,添加ViewBoxExtra.DisableScaling=“true”,例如