티스토리 뷰
http://www.wpf-tutorial.com/misc-controls/the-slider-control/
Slider의 속성 중 TickPlacement(Tick 위치) TickFrequency(Tick 빈도)
IsSnapToTickEnabled(Thumb를Tick에만 놓일 수 있는 지)를 이용하여 Slider를 꾸밀 수 있습니다.
1 2 3 4 5 | <StackPanel VerticalAlignment="Center" Margin="10"> <Slider Maximum="100" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True"> </Slider> </StackPanel> | cs |
Slider Value
Slider 컨트롤에는 Value 속성이 존재하며, Code-behid 혹은 바인딩을 할 수도 있습니다.
1 2 3 4 | <DockPanel VerticalAlignment="Center" Margin="10"> <TextBox Text="{Binding ElementName=slValue, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40" ></TextBox> <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slValue" /> </DockPanel> | cs |
Responding to changed values
Code-behind와 연결하기 위하여 Slider에는 ValueChanged event가 있습니다.
이를 설명하기 위한, RGB값에 대한 slider 예제입니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <StackPanel Margin="10" VerticalAlignment="Center"> <DockPanel VerticalAlignment="Center" Margin="10"> <Label DockPanel.Dock="Left" FontWeight="bold">R:</Label> <TextBox Text="{Binding ElementName=slider_ColorR, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40"></TextBox> <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slider_ColorR" ValueChanged="ColorSlider_ValueChanged"></Slider> </DockPanel> <DockPanel VerticalAlignment="Center" Margin="10"> <Label DockPanel.Dock="Left" FontWeight="bold">G:</Label> <TextBox Text="{Binding ElementName=slider_ColorG, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40"></TextBox> <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slider_ColorG" ValueChanged="ColorSlider_ValueChanged"></Slider> </DockPanel> <DockPanel VerticalAlignment="Center" Margin="10"> <Label DockPanel.Dock="Left" FontWeight="bold">B:</Label> <TextBox Text="{Binding ElementName=slider_ColorB, Path=Value, UpdateSourceTrigger=PropertyChanged}" DockPanel.Dock="Right" TextAlignment="Right" Width="40"></TextBox> <Slider Maximum="255" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="slider_ColorB" ValueChanged="ColorSlider_ValueChanged"></Slider> </DockPanel> </StackPanel> | cs |
1 2 3 4 5 | private void ColorSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { Color color = Color.FromRgb((byte)slider_ColorR.Value, (byte)slider_ColorG.Value, (byte)slider_ColorB.Value); this.Background = new SolidColorBrush(color); } | cs |
'C# > WPF' 카테고리의 다른 글
WPF tutorial - Using the WPF TabControl (0) | 2017.07.02 |
---|---|
WPF tutorial - The ProgressBar control (0) | 2017.07.02 |
WPF tutorial - The Border control (0) | 2017.07.02 |
WPF tutorial - The Ribbon control (0) | 2017.07.02 |
WPF tutorial - The WPF StatusBar control (0) | 2017.07.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- BFS
- 스택
- CollectionView
- Add TapGesture
- Fakebook
- XAML
- 데이터 바인딩
- 백준온라인
- 백준
- DP
- WPF
- command
- 그래프
- 문자열
- 타일링
- CustomCollectionViewCell
- Grid
- dfs
- BOJ
- MVVM
- 객체
- 코딩야학
- UIView Animation
- 생활코딩
- Cell Animation
- Custom Cell
- C++
- FEED
- listview
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함