Click here to Skip to main content
15,921,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i was trying to update tickbar of slider but i couldnt update frequently ..its working only once .it is not reflecting the changed values for the next times .but the values were being passed but the drawingcontext is not being overidden.

this below code is working only once .
its hitting for the second time but the values were not being chnaged .

What I have tried:

this is xaml--> slider

<pre><Slider   Height="27" x:Name="slider" TickPlacement="TopLeft"   Margin="5,0,0,0" IsMoveToPointEnabled="True"  Width="458"   Template="{DynamicResource Slider}"  Style="{DynamicResource Horizontal_Slider}">



this is my slider style
<wrbitmap:CustomTickBar x:Name="TopCustomTicker" Fill="{TemplateBinding Foreground}"   Height="3" Margin="0,-15,0,0"  Placement="Top" Grid.Row="0" Visibility="Visible"></wrbitmap:CustomTickBar>
<TickBar x:Name="BottomTick" Fill="White"   SnapsToDevicePixels="True" Grid.Row="2"   Placement="Top" Height="4"  Margin="0,-35,0,0" Visibility="Visible" />


code behind
<pre> public class CustomTickBar : TickBar
    {
        DrawingGroup backingStore = new DrawingGroup();

        DrawingVisual drawingVisual = new DrawingVisual();
//i was calling this method from other class so that i want to update new values 


        public void ResetTimes(long ImageStartTime, double TickFrequency)
        {

            this.StartPlayerTime = ImageStartTime;
            var drawingContext = backingStore.Open();
            // var  drawingContext = drawingVisual.RenderOpen();          
            OnRender(drawingContext);

            this.InvalidateVisual();

            drawingContext.Close();
            //CustomTickBar ticker =Application.Current.FindResource TopCustomTicker
        }

        public static double Tickfrequency;
        public long StartPlayerTime;
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {

            double num = this.Maximum - this.Minimum;
            double y = this.ReservedSpace * 0.5;
            FormattedText formattedText = null;
            double x = 0;
            //   TickFrequency
            for (double i = 0; i <= num; i += this.TickFrequency)
            {
                var time = TimeSpan.FromSeconds(StartPlayerTime);
                var ti = TimeSpan.FromSeconds(i);
                double t = (time + ti).TotalSeconds;
                var T = TimeSpan.FromSeconds(t);
                var TIME = T.Hours + ":" + T.Minutes;
                formattedText = new FormattedText(TIME.ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight,

                        new Typeface("Verdana"), 8, Brushes.White);
                //if (this.Minimum == i)
                //    x = 0;
                //else

                x += this.ActualWidth / (num / this.TickFrequency);
                dc.DrawText(formattedText, new Point(x - 80, y));

            }
}
Posted
Updated 19-Apr-18 2:08am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900