Page view counter
Slider Issue - From B1 to B2 Subscribe to this thread
Last post 09-08-2008 5:02 AM by avinashkr. 12 replies.
Sort Posts:
06-07-2008 10:25 AM
Slider Issue - From B1 to B2

 

 I have an application I am converting from beta 1 to beta 2. I use a slider to provide a zoom control. In beta 1 the following simple code worked fine:

private void sldZoomLevel_ValueChanged(object sender, RoutedEventArgs e)

   {

      ZoomLevel = (
int)sldZoomLevel.Value;

   }

In beta 2 during this method is being called during the app startup sequence, apparently before sldZoomLevel is defined. I get an exception since sldZoomLevel is null. A check for null resolved the issue but I'd like to understand why this happens and if it is limited to sliders.

Thanks for any help on this.

ercercerc

Loading...
Joined on 06-24-2007
Posts 36
06-07-2008 12:29 PM
Re: Slider Issue - From B1 to B2

I  have another issue with the B2 slider so I guess I'll just add on here. The Mouseleftbuttondown event doesn't seem to be firing anymore. I'm using a slider as my video scrubber, which uses a timer to update the value of the slider as the video plays. I suspend the timer when the user holds down the slider thumb so he can move the slider to a new position.

 But of course, it doesn't work anymore right now.

I'd say the event bubbling changes must be affecting it.

MarauderzMY

Loading...
Joined on 05-03-2007
Posts 218
06-07-2008 7:40 PM
Re: Re: Slider Issue - From B1 to B2

r.e. event bubbling...yes, you won't get the MouseLeftButtonDown because the Slider handles it.

Dave Relyea [MSFT]
http://blogs.msdn.com/devdave

Dave Relyea

Loading...
Joined on 05-09-2007
Posts 249
06-09-2008 2:19 AM
Re: Re: Slider Issue - From B1 to B2

Then what am i supposed to do in my situation if i need to know when a user starts dragging the slider. Any solutions other than make my own slider? Or how else do you recommend someone make a video scrubber with the slider now?

MarauderzMY

Loading...
Joined on 05-03-2007
Posts 218
06-10-2008 9:47 AM
Re: Re: Slider Issue - From B1 to B2
I have the exact same problem. I desperately need to handle both the MouseLeftButtonDown and MouseLeftButtonUp events for the Slider. I was hoping that I would be able to inherit from ScrollBar instead, but unfortunately it's sealed. If I had the source code I suppose I could modify the Slider code and compile my own tweaked version. Does anybody know if Microsoft will release the source code for the Beta 2 controls as they did for Beta 1?
hwsoderlund

Loading...
Joined on 11-09-2005
Posts 112
06-10-2008 9:59 AM
Re: Re: Slider Issue - From B1 to B2

I had face the same issue and wondering around how to solve it, instead of override slider control code but i think its the last option.

 you can download beta 2 sample code from here

 http://silverlight.net/Samples/2b2/SilverlightControls/run/default.html

 

Adi
Software Engineer
Softech Worldwide LLC

Aaadi

Loading...
Joined on 03-05-2008
Posts 29
06-10-2008 10:08 AM
Re: Re: Slider Issue - From B1 to B2

I am facing same issue with my media player. Another issue about slider style. I want to fill the left part of the slider(slider progress) with a color. There is only one repeatbutton and if I add something it appears on both left and right side.

Ok I solved the second problem. Silly me :). Just had to use

HorizontalTrackLargeChangeDecreaseRepeatButton .

 

Please Mark as Answer if this helps you.
Thanks n Regards
~Tanmoy
Blog: http://anothersilverlight.blogspot.com/

tanmoy.r

Loading...
Joined on 09-06-2007
Pune (India)
Posts 615
06-11-2008 3:07 AM
Re: Re: Slider Issue - From B1 to B2

I sort of have a solution that might solve the video scrubber issue. It involves creating your own derived slider control and adding event handlers for dragstarted and dragcompleted. These events already exist on the Thumb part of the slider, but not on the slider itself. So if we find the Thumb and just pass on the events we can detect when dragging starts and when it ends. Here's the code: 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Controls.Primitives;

using System.ComponentModel;

 

namespace CustomControls

{

    public class CustomSlider : Slider

    {

        /// <summary>

        /// Thrown when the thumb has been clicked, and dragging is initiated

        /// </summary>

        public event EventHandler<EventArgs> ThumbDragStarted;

 

        /// <summary>

        /// Thrown when the thumb has been released

        /// </summary>

        public event EventHandler<EventArgs> ThumbDragCompleted;

 

        public override void OnApplyTemplate()

        {

            base.OnApplyTemplate();

 

            //Set up drag event handlers

            Thumb thumb = this.GetTemplateChild("HorizontalThumb") as Thumb;

            if (thumb != null)

            {

                thumb.DragStarted += new DragStartedEventHandler(thumb_DragStarted);

                thumb.DragCompleted += new DragCompletedEventHandler(thumb_DragCompleted);

            }

        }

 

        void thumb_DragCompleted(object sender, DragCompletedEventArgs e)

        {

            OnThumbDragCompleted(this, new EventArgs());

        }

 

        void thumb_DragStarted(object sender, DragStartedEventArgs e)

        {

            OnThumbDragStarted(this, new EventArgs());

        }

 

        protected virtual void OnThumbDragStarted(object sender, EventArgs e)

        {

            if (ThumbDragStarted != null)

                ThumbDragStarted(sender, e);

        }

 

        protected virtual void OnThumbDragCompleted(object sender, EventArgs e)

        {

            if (ThumbDragCompleted != null)

                ThumbDragCompleted(sender, e);

        }

    }

}

 

hwsoderlund

Loading...
Joined on 11-09-2005
Posts 112
06-11-2008 8:33 AM
Re: Re: Re: Slider Issue - From B1 to B2

How can I implement click in the slider. Mousebuttonup event? 

Please Mark as Answer if this helps you.
Thanks n Regards
~Tanmoy
Blog: http://anothersilverlight.blogspot.com/

tanmoy.r

Loading...
Joined on 09-06-2007
Pune (India)
Posts 615
06-11-2008 8:54 AM
Re: Re: Re: Slider Issue - From B1 to B2

Hi,

i have created a customSlider control by inheriting Slider Control, now i want to apply Style/Template to my new CustomSlider control, can you please let me know how to do it?

Adi
Software Engineer
Softech Worldwide LLC

Aaadi

Loading...
Joined on 03-05-2008
Posts 29
06-11-2008 9:08 AM
Marked as Answer
Re: Re: Re: Slider Issue - From B1 to B2

First you need to set DefaultStyleKey in the constructor, like this:

        public CustomSlider() : base()

        {

            DefaultStyleKey = typeof(CustomSlider);

        }

 Then you need to create your own template in generic.xaml. The example below is a template where I've only made the Thumb slightly wider (for the horizontal template only).
 

<!--NavigationSlider-->
    <Style TargetType="gls:CustomSlider">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="gls:CustomSlider">
                    <Grid x:Name="Root">
                        <Grid.Resources>
                            <ControlTemplate x:Key="RepeatButtonTemplate">
                                <Grid x:Name="Root" Opacity="0" Background="Transparent"/>
                            </ControlTemplate>
                        </Grid.Resources>
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition Duration="0"/>
                                </vsm:VisualStateGroup.Transitions>
                                <vsm:VisualState x:Name="Normal"/>
                                <vsm:VisualState x:Name="MouseOver"/>
                                <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Root" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="FocusStates">
                                <vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualTransition Duration="0"/>
                                </vsm:VisualStateGroup.Transitions>
                                <vsm:VisualState x:Name="Unfocused"/>
                                <vsm:VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="(UIElement.Opacity)">
                                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Grid x:Name="HorizontalTemplate">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Rectangle Height="3" Margin="5,0,5,0" Grid.Column="0" Grid.ColumnSpan="3" Fill="#FFE6EFF7" Stroke="Black" StrokeThickness="0.5"/>
                            <RepeatButton x:Name="HorizontalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="0"/>

                            <!--Slightly wider-->
                            <Thumb Height="18" x:Name="HorizontalThumb" Width="23" Grid.Column="1"/>

                            <RepeatButton x:Name="HorizontalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="2"/>
                        </Grid>
                        <Grid x:Name="VerticalTemplate" Visibility="Collapsed">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Rectangle Margin="0,5,0,5" Width="3" Grid.Row="0" Grid.RowSpan="3" Fill="#FFE6EFF7" Stroke="Black" StrokeThickness="0.5"/>
                            <RepeatButton x:Name="VerticalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="2"/>
                            <Thumb Height="11" x:Name="VerticalThumb" Width="18" Grid.Row="1"/>
                            <RepeatButton x:Name="VerticalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="0"/>
                        </Grid>
                        <Rectangle x:Name="FocusVisual" IsHitTestVisible="false" Opacity="0" Stroke="#666666" StrokeDashArray=".2 5" StrokeDashCap="Round"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

hwsoderlund

Loading...
Joined on 11-09-2005
Posts 112
06-12-2008 2:46 AM
Re: Re: Re: Slider Issue - From B1 to B2

Thanks alot, i have also find this article that helps me to apply custom theme

http://blogs.msdn.com/jaimer/archive/2008/04/08/built-in-styling-and-generic-xaml.aspx

 

 

Adi
Software Engineer
Softech Worldwide LLC

Aaadi

Loading...
Joined on 03-05-2008
Posts 29
09-08-2008 5:02 AM
Re: Slider Issue - From B1 to B2
If that code wont work then use scale property with clip
avinashkr

Loading...
Joined on 09-08-2008
Hyderabad
Posts 13
Microsoft Communities