PercentRing.xaml 2.43 KB
<UserControl x:Class="FLY.ControlLibrary.PercentRing"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:sys="clr-namespace:System;assembly=mscorlib"      
             xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
             xmlns:local="clr-namespace:FLY.ControlLibrary"
             mc:Ignorable="d" >
    <UserControl.Resources >
        <local:Percent2AngleMultiConverter x:Key="p2aconv"/>
        <local:PercentMultiConverter x:Key="pconv"/>
        <local:TestUnit_PercentRing x:Key="testunit" Ratio="0.5" Total="1"  ColorText="#FF008BE5" ColorUnit="#FF464646"/>
    </UserControl.Resources>
    <Grid>
        <ed:Arc Width="114" Height="114"
                            ArcThickness="5" 
                            ArcThicknessUnit="Pixel" 
                            StartAngle="0" EndAngle="360" 
                            Fill="#FFF1F1F1" Stretch="None" Stroke="#FF988585" />
        <ed:Arc x:Name="arc_value" Width="114" Height="114"
                ArcThickness="5" 
                ArcThicknessUnit="Pixel" 
                StartAngle="0"  
                Fill="#FF008BE5" Stretch="None" Stroke="#FF988585" >
            <ed:Arc.EndAngle>
                <MultiBinding Converter="{StaticResource p2aconv}">
                    <Binding Path="Ratio"/>
                    <Binding Path="Total"/>
                </MultiBinding>
            </ed:Arc.EndAngle>
        </ed:Arc>
        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
            <Run x:Name="run_value" FontSize="30" FontFamily="Arial" >
                <Run.Text>
                    <MultiBinding Converter="{StaticResource pconv}" StringFormat="{}{0:F1}">
                    <Binding Path="Ratio"/>
                    <Binding Path="Total"/>
                </MultiBinding>
                </Run.Text>
                <Run.Foreground>
                    <Binding Path="ColorText"/>
                </Run.Foreground>
            </Run>
            <Run x:Name="run_unit" Text="%" FontSize="18">
                <Run.Foreground>
                    <Binding Path="ColorUnit"/>
                </Run.Foreground>
            </Run>
        </TextBlock>
    </Grid>
</UserControl>