2013-10-09 24 views
2

我有一個按鈕進入綁定到一個ICommand的控制ExceptionValidationRule在按鍵綁定到一個ICommand的

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

WPF窗口的,這是方法執行

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/>被設置好的,它不捕獲異常? 我的代碼有什麼問題?

回答

0

ExceptionValidationRule用於捕獲異常發生在屬性的set或get方法,但不是綁定到的命令屬性的執行方法。

+0

你知道另一個方法來完成這個任務嗎?我有很多綁定到Commands的對象,並且在每個命令中執行一些驗證,並且需要將它顯示給用戶,避免使用MessageBox。 Tks爲您提供幫助 –