private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var              window   = new DeliveryTemplateEditWindow();
         bool?            ret      = window.ShowDialog();
         DeliveryTemplate template = window.DeliveryTemplate;
         if (window.NeedUpdate && template.Id > 0)
         {
             var list = this.lstDeliveryTemplates.ItemsSource.OfType <DeliveryTemplate>().ToList();
             list.Add(template);
             this.lstDeliveryTemplates.ItemsSource = null;
             this.lstDeliveryTemplates.ItemsSource = list;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void btnEdit_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Button           btn = sender as Button;
         DeliveryTemplate vm  = btn.DataContext as DeliveryTemplate;
         var window           = new DeliveryTemplateEditWindow {
             DeliveryTemplate = vm
         };
         bool?ret = window.ShowDialog();
         if (window.NeedUpdate)
         {
             var list = this.lstDeliveryTemplates.ItemsSource;
             this.lstDeliveryTemplates.ItemsSource = null;
             this.lstDeliveryTemplates.ItemsSource = list;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }