从Contentpresenter获取ActualHeight / ActualWidth

时间:2018-07-17 08:05:28

标签: wpf xaml events binding custom-controls

我有这个XAML代码,我尝试访问Width的{​​{1}}的{​​{1}} / Height。之后,我做了一些研究,发现我需要获取ContentpresenterNaN,但是我无法访问它们。它们的值为FrameworkElement.ActualWidth

这里是FrameworkElement.ActualHeight(顺便说一句:这是一个自定义控件):

{{DependencyProperty.UnsetValue}}

1 个答案:

答案 0 :(得分:0)

将代码更改为:

    <ControlTemplate
                TargetType="{x:Type local:CADViewer}">
           <Border BorderThickness="2" BorderBrush="Black">
           <ContentPresenter Name="CadContent" Content="{Binding VisualContainer, RelativeSource={RelativeSource TemplatedParent}}">
                 <i:Interaction.Triggers>
                    <i:EventTrigger
                                    EventName="Loaded">
                       <i:InvokeCommandAction
                                        Command="{Binding CtrlLoaded, RelativeSource={RelativeSource TemplatedParent}}"/>
                    </i:EventTrigger>
                 </i:Interaction.Triggers>
                 <i:Interaction.Behaviors>
                    <local:EventToCommandBehavior
                            Command="{Binding ContentSizeChanged, RelativeSource={RelativeSource TemplatedParent}}"
                            Event="SizeChanged"
                            PassArguments="True" />
                 </i:Interaction.Behaviors>
              </ContentPresenter>
           </Border>
           <!--<TextBlock Text="{Binding VisualContainer.ActualHeight, RelativeSource={RelativeSource TemplatedParent}}"/>-->
        </ControlTemplate> 

现在,我得到了eventargs,并且可以通过以下方式访问ActualHeighte.Source.ActualHeight