c# - 在绑定(bind)到 ICommand 的 Button 处控制 ExceptionValidationRule

标签 c# wpf data-binding binding

我有一个按钮进入绑定(bind)到 ICommand 的 WPF 窗口

<Button Style="{StaticResource ToolBarButtonSearchTime}">
    <Button.Command>
        <Binding Path="FiltrarPlanillasCommand">
            <Binding.ValidationRules>
                <ExceptionValidationRule/>
            </Binding.ValidationRules>
        </Binding>
    </Button.Command>
</Button>

这是执行的方法

public void FiltrarPlanillasExecute(object p)
{
    FiltrosDocumento filtro = new FiltrosDocumento();
    filtro.ListaBodegasAcopio = ListaBodegasSeleccionadas;
    filtro.FechaInicial = FechaInicial;
    filtro.FechaFinal = FechaFinal;
    filtro.IntIdmodulo = IntIdModulo;
    try
    {
        filtro.PlanillaAcopioLiquidada = PlanillaAcopioLiquidada;

        ListaPlanillas = null;
        ListaPlanillas = new ObservableCollection<Merlin_MovimientoDocumentosFacturacion_Enc>(
                    ListaDocumentos.PlanillasAcopio(filtro, db)
                );
        ((DelegateCommand)_ICommandParadigmaNPrint).RaiseCanExecuteChanged();
    }
    catch (Exception)
    {
        //    Here this exception wasn't catched 
        throw;
    }
}

为什么如果<ExceptionValidationRule/>已设置,它没有捕获异常? 我的代码有什么问题?

最佳答案

ExceptionValidationRule 用于捕获属性的 set 或 get 方法发生的异常,而不是您绑定(bind)到的命令属性的 execute 方法。

关于c# - 在绑定(bind)到 ICommand 的 Button 处控制 ExceptionValidationRule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270748/

相关文章:

c# - 在矩形周围放置和粘贴控件

c# - c# 中 ReDimStatement 的等价物是什么?

c# - OnRender 方法不适用于超过 144 个控件

data-binding - MvvmCross AttributedText Converter 数据绑定(bind)生成空指针警告,但标签呈现正常——有什么问题吗?

c# - 将 Dictionary<T> 绑定(bind)到 WPF 列表框

c# - 为什么 System.Net.Sockets.Socket.AcceptAsync 在长时间不活动后完成 ConnectionReset?

c# - 如何将通用字典转换为其已知类型?

c# - 添加右键单击上下文菜单。

c# - 如何在 WPF 中实现使用祖先方法的命令?

c# - 我得到数据绑定(bind) : 'System.Data.DataRowView' does not contain a property with the name 'productID'