如何将wpf弹出窗口中的IsOpen属性设置为True?
我有这种 wpf 风格:
<Style x:Key="RequiredControlTemplate">
<Style.Setters>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<Popup IsOpen="{Binding ElementName=Adorner, Path=IsMouseOver}">
<TextBlock Text="{Binding ElementName=Adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />
</Popup>
<Border Grid.Column="1" BorderBrush="Red" BorderThickness="1" HorizontalAlignment="Stretch">
<AdornedElementPlaceholder Name="Adorner"/>
</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
我希望如果鼠标位于 Adorner 上,则 Popup 打开,但 IsOpen="{Binding ElementName=Adorner, Path=IsMouseOver}
不起作用...
I have this wpf style:
<Style x:Key="RequiredControlTemplate">
<Style.Setters>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<Popup IsOpen="{Binding ElementName=Adorner, Path=IsMouseOver}">
<TextBlock Text="{Binding ElementName=Adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />
</Popup>
<Border Grid.Column="1" BorderBrush="Red" BorderThickness="1" HorizontalAlignment="Stretch">
<AdornedElementPlaceholder Name="Adorner"/>
</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
I want that if mouse is over Adorner then Popup is open, but IsOpen="{Binding ElementName=Adorner, Path=IsMouseOver}
not work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我对你的风格做了一些改变。
添加了几个故事板来玩弹出打开...并触发装饰元素上的故事板
I made few changes in your style.
added couple of story boards to play with pop up open... and trigger storyboard on adorner element
将
Mode=OneWay
添加到绑定中。 IsOpen 默认为TwoWay
,只读属性不允许TwoWay
绑定。Add
Mode=OneWay
to binding. IsOpen isTwoWay
by default and read-only properties doesn't allowTwoWay
binding.如果您不遵循 MVVM 模式,您可以在 xaml 中指定
x:code
,您可以在其中处理 MouseOver 事件,并使用EventSetter
附加它。If you don't follow by MVVM pattern, you can specify
x:code
in your xaml, where you can handle MouseOver Event, and useEventSetter
to attach it.