wss1051 发表于 2015-5-9 09:40:05

Windows Phone 7 Slider控件的运用-调色板


  通过对红绿蓝三个Slider控件的赋值来综合起来三种颜色调试出来大面板的颜色。
  xaml





   
      
            
            
      
      
      
            
      
      
      
            
               
               
            
            
            
               
                  
                  
                  
               
               
                  
                  
                  
               
               
               
               
               
               
               
               
               
               
               
               
               
            
      
   
  cs




using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace ColorScroll
{
    public partial class MainPage : PhoneApplicationPage
    {
      public MainPage()
      {
            InitializeComponent();
            //三个slider控件的初始值
            redSlider.Value = 128;
            greenSlider.Value = 128;
            blueSlider.Value = 128;
      }
      //slider控件变化时触发的事件
      void OnSliderValueChanged(object sender, RoutedPropertyChangedEventArgs args)
      {
            Color clr = Color.FromArgb(255, (byte)redSlider.Value,
                                          (byte)greenSlider.Value,
                                          (byte)blueSlider.Value);//获取调剂的颜色

            rect.Fill = new SolidColorBrush(clr);//用该颜色的笔刷填充大面板

            redText.Text = clr.R.ToString("X2");
            greenText.Text = clr.G.ToString("X2");
            blueText.Text = clr.B.ToString("X2");
      }
      //手机方向变化触发的事件,从新布局
      protected override void OnOrientationChanged(OrientationChangedEventArgs args)
      {
            ContentPanel.RowDefinitions.Clear();
            ContentPanel.ColumnDefinitions.Clear();
            // Landscape
            if ((args.Orientation & PageOrientation.Landscape) != 0)
            {
                ColumnDefinition coldef = new ColumnDefinition();
                coldef.Width = new GridLength(1, GridUnitType.Star);
                ContentPanel.ColumnDefinitions.Add(coldef);
                coldef = new ColumnDefinition();
                coldef.Width = new GridLength(1, GridUnitType.Star);
                ContentPanel.ColumnDefinitions.Add(coldef);
                Grid.SetRow(controlGrid, 0);
                Grid.SetColumn(controlGrid, 1);
            }
            // Portrait
            else
            {
                RowDefinition rowdef = new RowDefinition();
                rowdef.Height = new GridLength(1, GridUnitType.Star);
                ContentPanel.RowDefinitions.Add(rowdef);
                rowdef = new RowDefinition();
                rowdef.Height = new GridLength(1, GridUnitType.Star);
                ContentPanel.RowDefinitions.Add(rowdef);
                Grid.SetRow(controlGrid, 1);
                Grid.SetColumn(controlGrid, 0);
            }
            base.OnOrientationChanged(args);
      }
    }
}
页: [1]
查看完整版本: Windows Phone 7 Slider控件的运用-调色板