我得到了这段XAML代码,并尝试访问NaN的Contentpresenter的Width/Height。在那之后,我做了一些研究,发现我需要获取FrameworkElement.ActualWidth和FrameworkElement.ActualHeight,但我无法访问它们。它们的值为{{DependencyProperty.UnsetValue}}
下面是XAML (顺便说一下:它是一个自定义控件):
<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>https://stackoverflow.com/questions/51376234
复制相似问题