Windows Phone 8.1 Slider

network | | 访问(57)
<StackPanel>
    <Grid Name="controlGrid" Grid.Row="0" Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0" Text="红色" Foreground="Red" FontSize="20" />
        <Slider x:Name="redSlider" Grid.Column="0" Grid.Row="1" Foreground="Red" Minimum="0" Maximum="255" ValueChanged="OnSliderValueChanged" />
        <TextBlock x:Name="redText" Grid.Column="0" Grid.Row="2" Text="0" Foreground="Red" FontSize="20"/>
        <TextBlock Grid.Column="1" Grid.Row="0" Text="绿色" Foreground="Green" FontSize="20"    />
        <Slider x:Name="greenSlider" Grid.Column="1" Grid.Row="1" Foreground="Green" Minimum="0" Maximum="255" ValueChanged="OnSliderValueChanged" />
        <TextBlock x:Name="greenText" Grid.Column="1" Grid.Row="2" Text="0" Foreground="Green" FontSize="20" />
        <TextBlock Grid.Column="2" Grid.Row="0" Text="蓝色" Foreground="Blue" FontSize="20"/>
        <Slider x:Name="blueSlider" Grid.Column="2" Grid.Row="1" Foreground="Blue" Minimum="0" Maximum="255" ValueChanged="OnSliderValueChanged" />
        <TextBlock x:Name="blueText" Grid.Column="2" Grid.Row="2" Text="0" Foreground="Blue" FontSize="20" />
    </Grid>
    <Ellipse Height="100" x:Name="ellipse1" Stroke="Black" StrokeThickness="1" Width="224" />
    <TextBlock x:Name="textBlock1" Text="颜色" FontSize="26"/>
</StackPanel>
public MainPage() {
    InitializeComponent();
    redSlider.Value = 128;
    greenSlider.Value = 128;
    blueSlider.Value = 128;
}

void OnSliderValueChanged(object sender, RangeBaseValueChangedEventArgs e) {
    Color clr = Color.FromArgb(255, (byte) redSlider.Value, (byte) greenSlider.Value, (byte) blueSlider.Value);
    ellipse1.Fill = new SolidColorBrush(clr);
    textBlock1.Text = clr.ToString();
    redText.Text = clr.R.ToString("X2");
    greenText.Text = clr.G.ToString("X2");
    blueText.Text = clr.B.ToString("X2");
}