More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Tuesday, 14 February 2017 8:44:28 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 509

WPF slider control with associated textbox and validation

WPF slider control can have a tick bar with tick marks, snap to ticks, set slider values in an associated text box, link the values in the textbox and slider control and vice versa.

XAML:
Code:
    <StackPanel x:Name="StackPanel1" Margin="10">
        <TextBlock Text="Text" Margin="0,0,5,0" />
        <DockPanel VerticalAlignment="Center" Margin="5">
            <Slider Maximum="100" Width="600" Margin="0,0,5,0" TickPlacement="BottomRight" TickFrequency="5" IsSnapToTickEnabled="True" Name="sl1" Value="{Binding ElementName=TextBox1, Path=Text}"  ValueChanged="Slider_ValueChanged" />
            <TextBox x:Name="TextBox1" DockPanel.Dock="Right" TextAlignment="Right" Width="30">
                <TextBox.Text>
                    <Binding Path="PropertyInViewModel" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <ExceptionValidationRule></ExceptionValidationRule>
                            <local:MyValidation></local:MyValidation>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
            </TextBox>
        </DockPanel>
    </StackPanel>



See custom validation local:MyValidation in https://bettereducation.....aspx?g=posts&t=6516
See Textbox binding update in WPF.

xaml.cs:
Code:
        private void Slider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
        {
            // ... Get Slider reference.
            var slider = sender as Slider;
            // ... Get Value.
            int value = (int)slider.Value;
            TextBox1.Text = value.ToString();
        }


View model:
public byte ValueInViewModel { get; set; }

Edited by user Wednesday, 22 February 2017 7:27:42 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.