Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Slider Issue - From B1 to B2
12 replies. Latest Post by avinashkr on September 8, 2008.
(0)
ercercerc
Member
93 points
38 Posts
06-07-2008 10:25 AM |
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:
{
}
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.
MarauderzMY
607 points
265 Posts
06-07-2008 12:29 PM |
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.
Dave Relyea
Participant
1084 points
249 Posts
06-07-2008 7:40 PM |
r.e. event bubbling...yes, you won't get the MouseLeftButtonDown because the Slider handles it.
06-09-2008 2:19 AM |
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?
hwsoderlund
411 points
118 Posts
06-10-2008 9:47 AM |
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?
Aaadi
40 points
33 Posts
06-10-2008 9:59 AM |
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
tanmoy.r
Contributor
3594 points
710 Posts
06-10-2008 10:08 AM |
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.
HorizontalTrackLargeChangeDecreaseRepeatButton .
06-11-2008 3:07 AM |
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;
/// Thrown when the thumb has been released
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);
06-11-2008 8:33 AM |
How can I implement click in the slider. Mousebuttonup event?
06-11-2008 8:54 AM |
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?
06-11-2008 9:08 AM |
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>
06-12-2008 2:46 AM |
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
avinashkr
12 points
13 Posts
09-08-2008 5:02 AM |
If that code wont work then use scale property with clip