Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:54:02+00:00 2026-05-27T22:54:02+00:00

I want to create a slider which looks like the last two on this

  • 0

I want to create a slider which looks like the last two on this image: http://www.java2s.com/Code/JavaImages/SliderTest.PNG
But I want the values that are shown on top to be linearly changed, 10,100,1000,10000.
And I want to let the user define these values.

When I created a style with hardcoded values it was ok:

                            <Grid x:Name="HorizontalTemplate" Margin="{StaticResource PhoneHorizontalMargin}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="12"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="100m" Grid.Column="0" TextAlignment="Left"></TextBlock>
                                <TextBlock Text="500m" Grid.Column="1" TextAlignment="Center"></TextBlock>
                                <TextBlock Text="1km"  Grid.Column="2" TextAlignment="Center"></TextBlock>
                                <TextBlock Text="10km"  Grid.Column="3" TextAlignment="Center"></TextBlock>
                                <TextBlock Text="100km" Grid.Column="4" TextAlignment="Center"></TextBlock>
                                <TextBlock Text="All" Grid.Column="5" TextAlignment="Center" ></TextBlock>                                
                            </Grid>
                            <Rectangle x:Name="HorizontalFill" Fill="{TemplateBinding Foreground}" Height="12"  IsHitTestVisible="False" Grid.Row="1"/>
                            <Rectangle x:Name="HorizontalTrack" Grid.Column="2" Fill="{TemplateBinding Background}" Height="12" IsHitTestVisible="False" Opacity="0.2" Grid.Row="1"/>
                            <RepeatButton x:Name="HorizontalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Row="1"/>
                            <RepeatButton x:Name="HorizontalTrackLargeChangeIncreaseRepeatButton" Grid.Column="2" IsTabStop="False" Template="{StaticResource PhoneSimpleRepeatButton}" Grid.Row="1"/>
                            <Thumb x:Name="HorizontalThumb" Grid.Column="1" Height="12"  Width="12" Grid.Row="1">
                                    <Thumb.Template>
                                        <ControlTemplate>
                                            <Canvas Background="{StaticResource PhoneForegroundBrush}" Height="12" Width="12">
                                                <Rectangle Fill="Transparent" Height="84" IsHitTestVisible="True" Canvas.Left="-24" Canvas.Top="-22" Width="60"/>
                                            </Canvas>
                                        </ControlTemplate>
                                    </Thumb.Template>
                                </Thumb>
                            </Grid>

But than I changed the grid defining the colums to this:

<Grid Name="separatorsGrid" DataContext="{Binding GridSeparator}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"/>

and added a dependency property to it:

     public static readonly DependencyProperty SeparatorProperty =
        DependencyProperty.Register("Separators", typeof(List<string>), typeof(CustomSlider), null);

      public static readonly DependencyProperty GridSeparatorProperty =
        DependencyProperty.Register("GridSeparator", typeof(Grid), typeof(CustomSlider), null);

    public CustomSlider()
    {
        DefaultStyleKey = typeof(CustomSlider);
    }

    public List<string> Separators
    {
        get{ return base.GetValue(SeparatorProperty) as List<string>; }
        set 
        {
            Grid maingrid = new Grid();
            foreach (string separator in value)
            {
                ColumnDefinition col = new ColumnDefinition();
                maingrid.ColumnDefinitions.Add(col);                    
            }

            int colNum = -1;
            foreach (string gridColumn in value)
            {
                colNum++;
                TextBlock textBlock = new TextBlock();
                textBlock.Text = gridColumn;
                Grid.SetRow(textBlock, 0);
                Grid.SetColumn(textBlock, colNum);
                maingrid.Children.Add(textBlock);  // This line makes all the difference.
            }
            base.SetValue(GridSeparatorProperty, maingrid); 
        }
    }

    public Grid GridSeparator
    {
        get { return base.GetValue(GridSeparatorProperty) as Grid; }
        set { base.SetValue(GridSeparatorProperty, value); }
    }

and for some reason this isn’t working, the dependency property is not even called once. o.O or if someone has a similar solution for this that would be nice.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:54:02+00:00Added an answer on May 27, 2026 at 10:54 pm

    First of all, you never should put a code inside DependencyProperty getters and setters. It’s not guaranteed that this code will be executed – in some cases there are direct manipulations occurs on dependency properties.

    Also, when you have a binding, the source must be a public property.

    And the last, how are you going to add elements and columns to a grid using DataContext of the Grid?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a field that looks like this ....can any one tell
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
i want a jquery code which create a div contains a given content and
I want to create a simple slider like the one I ve shown in
I want to create a slider to control the volume of the media player.
I want create wordpress website into which I want create user management... That means
i want create image animation , i have 50 images with png format now
I am building a custom control that looks like the one in the image
I want a list view control (or any list like control) in which each
I have created an image slider. This slider appears on every page of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.