<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DemoSlider.RGBSlider">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness"
iOS="10, 20, 10, 10"
Android="10, 0, 10, 10"
WinPhone="10, 0, 10, 10" />
</ContentPage.Padding>
<StackLayout>
<StackLayout.Resources>
<ResourceDictionary>
<Style TargetType="Slider">
<Setter Property="Maximum" Value="255" />
</Style>
<Style TargetType="Label">
<Setter Property="FontSize" Value="Large" />
<Setter Property="HorizontalTextAlignment" Value="Center" />
</Style>
</ResourceDictionary>
</StackLayout.Resources>
<Slider x:Name="redSlider"
ValueChanged="OnSliderValueChanged" />
<Label x:Name="redLabel" />
<Label x:Name="greenLabel" />
<Label x:Name="blueLabel" />
<Slider x:Name="greenSlider"
ValueChanged="OnSliderValueChanged" />
<Slider x:Name="blueSlider"
ValueChanged="OnSliderValueChanged" />
<BoxView x:Name="boxView"
VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace DemoSlider
{
public partial class RGBSlider : ContentPage
{
public RGBSlider()
{
InitializeComponent();
redSlider.Value = 128;
greenSlider.Value = 128;
blueSlider.Value = 128;
}
void OnSliderValueChanged(object sender, ValueChangedEventArgs args)
{
if (sender == redSlider)
{
redLabel.Text = String.Format("Red = {0:X2}", (int)redSlider.Value);
}
else if (sender == greenSlider)
{
greenLabel.Text = String.Format("Green = {0:X2}", (int)greenSlider.Value);
}
else if (sender == blueSlider)
{
blueLabel.Text = String.Format("Blue = {0:X2}", (int)blueSlider.Value);
}
boxView.Color = Color.FromRgb((int)redSlider.Value,
(int)greenSlider.Value,
(int)blueSlider.Value);
}
}
}
댓글 없음:
댓글 쓰기
참고: 블로그의 회원만 댓글을 작성할 수 있습니다.