这是我想要做的。
这是我用来尝试解决问题的一些xaml。到目前为止的问题/问题:
干杯,
Berryl
<ToggleButton x:Name="editNameOpen" Style="{StaticResource EditToggleButtonStyle}" Grid.Column="1" Grid.Row="0"/>
<Popup x:Name="popupNameEditingControl"
PlacementTarget="{Binding ElementName=editeditNameOpenName}"
PopupAnimation="Slide"
StaysOpen="False" ** shoulf this be true?
MinWidth="50">
** open and stay open while until editNameClose is checked
<Popup.IsOpen>
<MultiBinding >
<Binding Mode="OneWay" ElementName="editNameOpen" Path="IsChecked"/>
<Binding Mode="OneWay" ElementName="editNameClose" Path="IsChecked" Converter="{StaticResource invertBoolConv}"/>
</MultiBinding>
</Popup.IsOpen>
** how do we reset editNameOpen to be NOT IsChecked when editNameClose is checked?
** how do we reset editNameClose to be NOT IsChecked and then reset editNameClose to also be not checked when this opens again?
<StackPanel Orientation="Horizontal" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<Label Content="Hello Wolrd!"/>
<ToggleButton x:Name="editNameClose" Content="X"/>
</StackPanel>
</Popup>
答案 0 :(得分:2)
我个人会将Popup.IsOpen
和ToggleButtons
绑定到DataContext
因此,当第一个ToggleButton
被检查时,它会将布尔值设置为true
,这会使Popup.IsOpen
评估为true
并打开Popup
< / p>
第二个ToggleButton
可能需要使用Converter
来反转布尔属性,因此在IsOpen = true
时显示为未选中,并且检查它将使IsOpen = false
,这将自动关闭Popup
并取消选中第一个ToggleButton
至于您收到的错误,MultiBinding
期望Converter
类型为IMultiValueConverter
,因为您无法将一个属性绑定到两个单独的值。您需要一个转换器将这些值转换为您可以使用的单个值。
如果你真的想这样做,而不是使用DataContext
中的属性,请尝试绑定IsOpen
的{{1}}属性和Popup
属性你的IsChecked
一起。
ToggleButtons