【发布时间】:2017-07-31 09:01:57
【问题描述】:
我的 Xaml 中有一个 ContentControl,我想在 ViewModel 中访问它的高度,我尝试在我的 ViewModel 中创建一个属性并通过 TwoWay 将它绑定到 ContentControl。但问题在于它将 ContentControl 高度设置为 0,这是该属性的默认值。
代码:
Xaml
<ContentControl x:Name="ContentControl"
Content="{Binding ContentFrame}"
HorizontalContentAlignment="Stretch"
Height="{Binding ContentControlHeight, Mode=TwoWay}"
VerticalContentAlignment="Stretch"></ContentControl>
ViewModel(使用 Fody 进行属性更改通知):
public double ContentControlHeight { get;放; }
【问题讨论】:
-
你能添加你使用的代码吗?
-
可以绑定Content控件的Loaded事件,获取控件的高度
-
@Arcana,谢谢。但我不想直接在后面的代码中访问控制。另请参阅我更新后的代码。
-
@Romasz。谢谢。会试一试的。
-
如果您在项目中使用
Template10,您可以在视图模型中创建DelegateCommand并将其绑定到Loaded事件
标签: c# xaml mvvm uwp winrt-xaml