WPF: gauge value converter

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

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

TotalPacketsSent

T

相关标签:
1条回答
  • 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:

    <Controllers:Gauge x:Name="gauge" Minimum="0" Maximum="100">
        <Controllers:Gauge.Value>
            <MultiBinding Converter="{StaticResource GaugeValueConverter}">
                <Binding Path="(my:MyClass.TotalPacketsSent)" />
                <Binding Path="(my:MyClass.TotalPacketsInList)" />
            </MultiBinding>
        </Controllers:Gauge.Value>
    </Controllers:Gauge>
    
    0 讨论(0)
提交回复
热议问题