【问题标题】:WPF Popup Button QuestionWPF 弹出按钮问题
【发布时间】:2009-07-29 20:37:38
【问题描述】:

在 WPF 中,我希望有一个按钮,当单击它时,它会打开或关闭弹出窗口,具体取决于它是否已经打开(如果它打开则关闭它,如果它关闭则打开它),我想这样做纯粹在 XAML 中。这可能吗?

谢谢,
罗伊

【问题讨论】:

    标签: wpf xaml button popup


    【解决方案1】:

    是的,您需要使用ToggleButton 而不是标准按钮。然后您应该能够将 Popup.IsOpen 属性绑定到 ToggleButton.IsChecked 属性。

    如果您需要一个 XAML sn-p 来演示这一点,我可以在几分钟内制作一个。但这应该足够简单。

    【讨论】:

    【解决方案2】:

    这是作为行为实现的问题的nice solution,因此独立于 ViewModel 后面的代码。

    【讨论】:

      【解决方案3】:

      正如@Charlie 所说,我只是解决了这个问题。 这是我在page.xaml 文件中的代码。

      <ToggleButton Name="MenuButton" Width="120" Height="40"/>
                  <Popup Width="130" Height="150" PlacementTarget="{Binding ElementName=MenuButton}" Placement="Bottom" AllowsTransparency="True" PopupAnimation="Fade" IsOpen="{Binding ElementName=MenuButton,Path=IsChecked}" StaysOpen="False">
                      <Border Background="Black" CornerRadius="10">
                          <Grid >
                              <Grid.RowDefinitions>
                                  <RowDefinition />
                                  <RowDefinition />
                                  <RowDefinition />
                              </Grid.RowDefinitions>
                              <Grid Grid.Row="0">
                                  <Button Content="Log" Width="120" Height="40"/>
                              </Grid>
                              <Grid Grid.Row="1">
                                  <Button Content="Shut Down" Width="120" Height="40"/>
                              </Grid>
                             <Grid Grid.Row="2">
                                  <Button Content="About..." Width="120" Height="40"/>
                              </Grid>
                          </Grid>
                      </Border>
                  </Popup>
      

      【讨论】:

        猜你喜欢
        • 2018-03-09
        • 1970-01-01
        • 2012-09-27
        • 1970-01-01
        • 2016-03-02
        • 2011-09-07
        • 2012-05-31
        • 2011-02-10
        • 1970-01-01
        相关资源
        最近更新 更多