.Net Project/SilverLight 3.0

51장 Slider 컨트롤

Magic_kit 2009. 12. 2. 16:01
반응형
  Slider 컨트롤
- 특정한 범위의 값 내에서 사용자로부터 임의의 값을 선택 받는 UI에 사용 가능
- Orientation 프로퍼티를 설정하여 컨트롤의 방향을 설정 할 수 있으며, 프로퍼티를 설정하여
  값이 증가하는 방향을 설정 가능

 Slider.Xaml

UserControl x:Class="RiaSlider.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <MediaElement x:Name="media" Width="640" Height="480"

                          Source="Silverlight.wmv">           

        </MediaElement>      

        <TextBlock Text="Volume"></TextBlock>

 

        <Slider x:Name="slider"

                Maximum="1" Minimum="0"

                Width="200" Value="0.5" Height="50" SmallChange="0.1">           

        </Slider> 

    </Grid>

</UserControl> 

  Slider.Cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSlider

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            this.slider.ValueChanged += new
            RoutedPropertyChangedEventHandler
<double>(slider_ValueChanged);

        }

 

        void slider_ValueChanged(object sender,
                                  RoutedPropertyChangedEventArgs
<double> e)

        {

            // 0~1까지 볼륨 조절 가능

            this.media.Volume = this.slider.Value;

        }

    }

} 





반응형