【问题标题】:ValidationRule is firing when i hit cancel button当我点击取消按钮时,ValidationRule 正在触发
【发布时间】:2015-11-27 20:44:54
【问题描述】:

我有一个数据网格,其中包含一些项目和验证规则,用于检查网格中的项目是否正确。

还有一个关闭按钮,问题是当您单击它时,验证器正在检查添加的值是否正确,如果不正确,则会提示错误,但我只想关闭窗口并跳过验证数据。

原因是当您单击取消按钮时,您也会失去触发验证的焦点

代码应该更好地解释它:

<DataGrid  Name="MyGrid" Loaded="GetSth" ItemsSource="{Binding}" AutoGenerateColumns="False" >
                <DataGrid.RowValidationRules>
                    <configuration:SomeCoolValidationRule ValidationStep="UpdatedValue"/>
                </DataGrid.RowValidationRules>

                      <DataGrid.Columns>
                        <!-- some columns  -->
                      </DataGrid.Columns>

                <Button Grid.Row="1" Content="Close" VerticalAlignment="Bottom" Click="CloseClick"/>      
  </DataGrid>

以及后面的代码:

  <!-- Code behind -->
  private void CloseClick(object sender, RoutedEventArgs e)
  {
            <!-- When clicked i just want window to close, not to check validator rules -->
            Close(); 

  }

【问题讨论】:

    标签: wpf xaml validationrules


    【解决方案1】:

    解决方案是将按钮上的可聚焦属性设置为 false。

    这样您在单击关闭按钮且验证器未启动时不会更改 datagrid itemsSource。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      相关资源
      最近更新 更多