SilverLight调色器

 

 

xaml代码:

  <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="260">
            
            </ColumnDefinition>
            <ColumnDefinition Width="400"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="120">
              
               
            </RowDefinition>
    
            <RowDefinition Height="120"></RowDefinition>
  
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="0" Grid.Column="1" x:Name="PreviewColor" Fill="#FF6600" Margin="10" Stroke="#666666" StrokeThickness="2"></Rectangle>
        <StackPanel Grid.Row="1" Grid.Column="1">
            <TextBlock FontSize="12">Color</TextBlock>
            <TextBox x:Name="HexColor" Width="160" Height="30" Text="#FF6600" Margin="10,5" FontSize="11"></TextBox>
        </StackPanel>
       
        <StackPanel Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" VerticalAlignment="Center">
            <TextBlock Text="Alpha" FontSize="12" Margin="10,15,0,0"></TextBlock>
            <Slider x:Name="AlphaSlider" Margin="20,0,10,0" Maximum="255" Value="255" ValueChanged="AlphaSlider_ValueChanged"></Slider>
            <TextBlock Text="Red" FontSize="12" Margin="10,15,0,0"></TextBlock>
            <Slider x:Name="RedSlider" Margin="20,0,10,0" Maximum="255" Value="255" ValueChanged="RedSlider_ValueChanged"></Slider>
            <TextBlock Text="Green" FontSize="12" Margin="10,15,0,0"></TextBlock>
            <Slider x:Name="GreenSlider" Margin="20,0,10,0" Maximum="255" Value="102" ValueChanged="GreenSlider_ValueChanged"></Slider>
            <TextBlock Text="Blue" FontSize="12" Margin="10,15,0,0"></TextBlock>
            <Slider x:Name="BlueSlider" Margin="20,0,10,0" Maximum="255" Value="0" ValueChanged="BlueSlider_ValueChanged"></Slider>
        </StackPanel>

    </Grid>

xaml.cs代码:

  #region 初始化界面
        public GridColor()
        {
            InitializeComponent();
            //重新注册AlphaSlider_ValueChanged
            this.AlphaSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(AlphaSlider_ValueChanged);
            //重新注册RedSlider_ValueChanged
            this.RedSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(RedSlider_ValueChanged);
            //重新注册RedSlider_ValueChanged
            this.GreenSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(GreenSlider_ValueChanged);
            //重新注册RedSlider_ValueChanged
            this.BlueSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(BlueSlider_ValueChanged);
       
        }

        /// <summary>
        /// 功能描述:调整调色器显示颜色,并显示调整后的颜色值
        /// </summary>
        private void mm_AdjustColor()
        {
            if (AlphaSlider==null||RedSlider==null||GreenSlider==null||BlueSlider==null)
            {
                return;
            }
            Color color = Color.FromArgb((byte)AlphaSlider.Value, (byte)RedSlider.Value, (byte)GreenSlider.Value, (byte)BlueSlider.Value);
            PreviewColor.Fill = new SolidColorBrush(color);
            HexColor.Text = color.ToString();

        }
        #endregion
        #region 主界面操作
       

        // 当用户导航到此页面时执行。
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        /// <summary>
        /// 功能描述:改变红色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RedSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            mm_AdjustColor();

        }

        /// <summary>
        /// 功能描述:改变原色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AlphaSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            mm_AdjustColor();

        }

        /// <summary>
        /// 功能描述:改变绿色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GreenSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            mm_AdjustColor();

        }

        /// <summary>
        /// 功能描述:改变蓝色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BlueSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            mm_AdjustColor();

        }
        #endregion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值