WPF-xaml Calculating Total of text box values

前端 未结 2 592
攒了一身酷
攒了一身酷 2020-12-19 18:58

I have a wpf xaml form which has 5 text boxes shows order price. Below the 5 text boxes i have another textbox:[subTotal] which displays the subtotal of order price\'s.\"Su

2条回答
  •  悲哀的现实
    2020-12-19 19:30

    Using this converter:

    public class SumConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            double _Sum = 0;
            if (values == null)
                return _Sum;
            foreach (var item in values)
            {
                double _Value;
                if (double.TryParse(item.ToString(), out _Value))
                    _Sum += _Value;
            }
            return _Sum;
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes,
            object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Do this:

    
        
    
    
        
        
        
        
        
        
            
                
                    
                    
                    
                    
                    
                
            
        
    
    

    Looks like:

    screenshot

提交回复
热议问题