在绑定到ICommand的Button处控制ExceptionValidationRule

时间:2013-10-09 11:26:11

标签: c# wpf data-binding binding

我在一个绑定到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/>被设置,它没有捕获异常? 我的代码怎么了?

1 个答案:

答案 0 :(得分:0)

ExceptionValidationRule用于捕获属性的set或get方法发生的异常,但不捕获绑定到的命令属性的execute方法。