我有一个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中(使用基于http://shevaspace.blogspot.com/2007/02/visual-level-programming-vs-logical.html的技术)有一个按钮控件,定义为
<Button>
<Image Source="/AcchImageLoad;component/icons/metroStudio/ImageRotation.png" Stretch="None" />
</Button>如何让AdornerLayer中的此按钮使用图像的本机分辨率,而不是使用ViewBox进行拉伸?
发布于 2013-05-10 05:11:21
基本上,我们的想法是通过绑定转换器从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>另请参阅:
发布于 2018-01-05 18:39:00
您可以使用以下解决方案禁用视图框缩放:Disable Viewbox Resize for Specific Elements
基本上,为ViewBox_SizeChanged添加一个处理程序,并将exempt元素的转换设置为ViewBox的转换的反转。
然后在XAML中添加ViewBoxExtra.DisableScaling="true",例如
<Rectangle Width="50" Height="50" local:ViewBoxExtra.DisableScaling="true"/>https://stackoverflow.com/questions/16468368
复制相似问题