首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Contentpresenter获取ActualHeight/ActualWidth

从Contentpresenter获取ActualHeight/ActualWidth
EN

Stack Overflow用户
提问于 2018-07-17 16:05:28
回答 0查看 213关注 0票数 0

我得到了这段XAML代码,并尝试访问NaNContentpresenterWidth/Height。在那之后,我做了一些研究,发现我需要获取FrameworkElement.ActualWidthFrameworkElement.ActualHeight,但我无法访问它们。它们的值为{{DependencyProperty.UnsetValue}}

下面是XAML (顺便说一下:它是一个自定义控件):

代码语言:javascript
复制
   <local:MultiBindingConv
        x:Key="MultiBindingConv" />
   <Style TargetType="{x:Type local:CADViewer}">
        <Setter Property="Template">
            <Setter.Value>
            <ControlTemplate
                    TargetType="{x:Type local:CADViewer}">
               <ContentPresenter Name="CadContent" Content="{Binding VisualContainer, RelativeSource={RelativeSource TemplatedParent}}">
                  <i:Interaction.Triggers>
                     <i:EventTrigger
                                        EventName="SizeChanged">
                        <i:InvokeCommandAction
                                            Command="{Binding ContentSizeChanged, RelativeSource={RelativeSource TemplatedParent}}">
                           <i:InvokeCommandAction.CommandParameter>
                              <MultiBinding Converter="{StaticResource MultiBindingConv}">
                                 <Binding ElementName="CadContent" Path="FrameworkElement.ActualWidth"/>
                                 <Binding ElementName="CadContent" Path="FrameworkElement.ActualHeight"/>
                              </MultiBinding>
                           </i:InvokeCommandAction.CommandParameter>
                        </i:InvokeCommandAction>
                     </i:EventTrigger>
                  </i:Interaction.Triggers>
               </ContentPresenter>
               <!--<TextBlock Text="{Binding VisualContainer.ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/>-->
            </ControlTemplate>
         </Setter.Value>
        </Setter>
    </Style>
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51376234

复制
相关文章

相似问题

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