【问题标题】:Close xceed Child Window on escape button click单击退出按钮时关闭 xceed 子窗口
【发布时间】:2013-10-20 16:40:14
【问题描述】:

我正在使用 xceed wpf 工具包。 我正在使用 ChildWindow。我需要在按下退出键时关闭打开的子窗口。这是代码

<xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit" >
//My Content Here
</xctk:ChildWindow>

你能帮我吗??

【问题讨论】:

    标签: c# wpf xaml wpftoolkit childwindow


    【解决方案1】:

    在您的 Button 上使用“IsCancel”属性。

    <Button Content="Discard" Click="ButtonDiscard_OnClick" IsCancel="True"></Button>
    

    IsDefault 相同(输入键)

    【讨论】:

      【解决方案2】:

      如果您使用 2.0.0 或更高版本,则应将 ChildWindow 放入 WindowContainer 并使用 PreviewKeyDown 事件。

      XAML:

      <xctk:WindowContainer>
          <xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"                          
                        PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >                
          </xctk:ChildWindow>
      </xctk:WindowContainer>
      

      代码隐藏:

      private void ChildVendorsEdit_PreviewKeyDown(object sender, KeyEventArgs e)
      {
          if (e.Key == Key.Escape)
          {
              (sender as Xceed.Wpf.Toolkit.ChildWindow).WindowState = Xceed.Wpf.Toolkit.WindowState.Closed;
          }
      }
      

      如果你使用低于 2.0.0 的版本,你应该使用 PreviewKeyDown 事件:

      XAML:

      <xctk:ChildWindow x:Name="ChildVendorsEdit" IsModal="True" WindowStartupLocation="Center" Caption="Edit"                          
                        PreviewKeyDown="ChildVendorsEdit_PreviewKeyDown" >            
      </xctk:ChildWindow>
      

      代码隐藏:

      private void ChildVendorsEdit_PreviewKeyDown(object sender, KeyEventArgs e)
      {
          if (e.Key == Key.Escape)
          {
              (sender as Xceed.Wpf.Toolkit.ChildWindow).WindowState = Xceed.Wpf.Toolkit.WindowState.Closed;
          }
      }
      

      要在PreviewKeyDown 事件处理程序中关闭ChildWindow,您有两种选择:

      • 可以将WindowState设置为Closed
      • 或者你可以调用Close方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-23
        • 1970-01-01
        • 1970-01-01
        • 2012-09-26
        • 2014-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多