Having trouble with a thumb in a Pivot control.

startrunner

New member
Jan 21, 2014
24
0
0
Visit site
Hello, fellow developers! I am developing a music player and I am trying to implement the 'Swipe on album art for next track' feature using a Thumb. My control works just fine unless I put it in a Pivot control For some reason, a Thumb in a Pivot/Panorama simply does not work. I tried to 'lock' the pivot control by changing property values and editing the template of the control but to no avail. All solutions I could find on the internet were for Silverlight applications and didn't work for me. As far as I know all music applications that have this feature, including XBM and Zune are Silverlight apps. Here is the XAML and code of my Control. Does anyone have any ideas? Thanks in advance.
Code:
<Grid>
        <TextBlock Margin="8" VerticalAlignment="Bottom" TextAlignment="Center" FontSize="18">Next Track</TextBlock>
        <TextBlock Margin="8" VerticalAlignment="Top" TextAlignment="Center" FontSize="18">Previous Track</TextBlock>
        <Thumb Name="thumbControl" Opacity="1" DragDelta="thumbControl_DragDelta" VerticalAlignment="Center" DragCompleted="thumbControl_DragCompleted" Height="{Binding ElementName=nowPlayingPicture, Path=ActualWidth}">
            <Thumb.Background>
                <ImageBrush Stretch="Fill" ImageSource="ms-appx:///Assets/albumArtPlaceholder.jpg"/>
            </Thumb.Background>
        </Thumb>
    </Grid>

Code:
 public sealed partial class NowPlayingPicutre : UserControl
    {
        public NowPlayingPicutre()
        {
            this.InitializeComponent();
            this.Loaded += NowPlayingPicutre_Loaded;
            this.LayoutUpdated += NowPlayingPicutre_LayoutUpdated;
        }

        public DependencyProperty nextTrackCommandProperty = DependencyProperty.Register("NextTrackCommand", typeof(ICommand), typeof(NowPlayingPicutre), PropertyMetadata.Create(false));
        public ICommand NextTrackCommand
        {
            get { return GetValue(nextTrackCommandProperty) as ICommand; }
            set { SetValue(nextTrackCommandProperty, value as ICommand); }
        }

        public DependencyProperty previousTrackCommandProperty = DependencyProperty.Register("PreviousTrackCommand", typeof(ICommand), typeof(NowPlayingPicutre), PropertyMetadata.Create(false));
        public ICommand PreviousTrackCommand
        {
            get { return GetValue(previousTrackCommandProperty) as ICommand; }
            set { SetValue(previousTrackCommandProperty, value as ICommand); }
        }

        void NowPlayingPicutre_LayoutUpdated(object sender, object e)
        {
            this.Height = this.ActualWidth;
        }

        void NowPlayingPicutre_Loaded(object sender, RoutedEventArgs e)
        {
            thumbControl.Height = this.ActualHeight;
        }

        private enum DragDirection { Up, Down, Unset };
        DragDirection dragDirection = DragDirection.Unset;

        private void thumbControl_DragDelta(object sender, DragDeltaEventArgs e)
        {
            try
            {
                if (dragDirection == DragDirection.Unset)
                {
                    if (e.VerticalChange > 0) dragDirection = DragDirection.Down;
                    else dragDirection = DragDirection.Up;
                }

                if (dragDirection == DragDirection.Down) thumbControl.VerticalAlignment = VerticalAlignment.Bottom;
                else thumbControl.VerticalAlignment = VerticalAlignment.Top;

                double newHeight = thumbControl.Height;
                if (dragDirection == DragDirection.Up) newHeight += e.VerticalChange;
                else newHeight -= e.VerticalChange;

                if (newHeight < 0.9 * this.ActualHeight) newHeight = 0.9 * this.ActualHeight;
                if (newHeight > this.ActualHeight) newHeight = this.ActualHeight;

                thumbControl.Height = newHeight;
            }
            catch { }
        }

        private void thumbControl_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (thumbControl.Height <= 0.95 * this.ActualHeight)
            {
                try
                {
                    if(dragDirection==DragDirection.Down)PreviousTrackCommand.Execute(null);
                    if (dragDirection == DragDirection.Up) NextTrackCommand.Execute(null);
                }
                catch { }
            }
                dragDirection = DragDirection.Unset;
                thumbControl.Height = this.ActualHeight;            
        }
    }
 

ibats

New member
Nov 2, 2014
15
0
0
Visit site

Members online

Forum statistics

Threads
324,509
Messages
2,245,649
Members
428,220
Latest member
Wakeboards