我正在使用 IsOpen
绑定(bind)到一些难以访问 附加属性来打开 Popup。我只想以某种方式将 IsOpen
值传递给 ViewModel。
为此尝试使用 setter:
<Popup StaysOpen="False"
IsOpen="{Binding Path=(local:ListViewBehavior.IsColumnHeaderClicked), RelativeSource={RelativeSource FindAncestor, AncestorType=GridViewColumnHeader}}">
<Popup.Style>
<Style TargetType="Popup">
<Style.Triggers>
<Trigger Property="IsOpen" Value="True">
<!-- this is not possible -->
<Setter Property="{Binding IsPopupOpened ...}" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
</Popup.Style>
</Popup>
给予:
A 'Binding' cannot be set on the 'Property' property of type 'Setter'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
有没有办法将 IsOpen
值(已经绑定(bind)到 View 中的其他内容)传递给 ViewModel?
最佳答案
您可以创建一个附加属性,该属性由事件处理程序设置为弹出窗口的打开和关闭事件。这可以通过 OneWayToSource 绑定(bind)绑定(bind)到 ViewModel 的 IsPopupOpen 属性。 我也不太确定是否有更简单的解决方案,但这是我会做的一种“解决方法”,以防没有人在这里提供更好的解决方案。
关于c# - 是否可以使用触发器 setter 来更改 ViewModel 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36080405/