WPF: gauge value converter

后端 未结 1 1904
死守一世寂寞
死守一世寂寞 2021-01-29 10:31

So i have simple Gauge class with static int property that implement Propertychanged:

TotalPacketsSent

T

1条回答
  •  猫巷女王i
    2021-01-29 11:13

    You're casting the value argument as an int and then not using it.

    I imagine what you're looking for is something like (deriving from IMultiValueConverter rather than IValueConverter):

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        double totalPacketsSent = (double)values[0];
        double totalPacketsInList = (double)values[1];
    
        // further validation for handling divide by zero, etc. may need to go here
    
        return totalPacketsSent / totalPacketsInList * 100
    }
    

    And in the XAML:

    
        
            
                
                
            
        
    
    

    0 讨论(0)
提交回复
热议问题