首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ViewBox拉伸中免除AdornerLayer中的控件

从ViewBox拉伸中免除AdornerLayer中的控件
EN

Stack Overflow用户
提问于 2013-05-10 02:15:52
回答 2查看 581关注 0票数 1

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

代码语言:javascript
复制
<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的技术)有一个按钮控件,定义为

代码语言:javascript
复制
<Button>
    <Image Source="/AcchImageLoad;component/icons/metroStudio/ImageRotation.png" Stretch="None" />
</Button>

如何让AdornerLayer中的此按钮使用图像的本机分辨率,而不是使用ViewBox进行拉伸?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-10 05:11:21

基本上,我们的想法是通过绑定转换器从ViewBox获得转换并应用相反的转换。

绑定转换器可以通过以下代码获得反转:

代码语言:javascript
复制
((ContainerVisual)VisualTreeHelper
.GetChild((System.Windows.DependencyObject)viewbox, 0)).Transform.Inverse

在xaml中,绑定看起来像这样

代码语言:javascript
复制
<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>

另请参阅:

票数 1
EN

Stack Overflow用户

发布于 2018-01-05 18:39:00

您可以使用以下解决方案禁用视图框缩放:Disable Viewbox Resize for Specific Elements

基本上,为ViewBox_SizeChanged添加一个处理程序,并将exempt元素的转换设置为ViewBox的转换的反转。

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

代码语言:javascript
复制
<Rectangle Width="50" Height="50" local:ViewBoxExtra.DisableScaling="true"/>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16468368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档