2012-07-09 82 views
0

我在wp7中創建了一個滑塊來控制backgroundaudio播放器的音量。滑塊控件行爲變化

<Slider x:Name="VolumeSlider" Height="89" Margin="12,0,24,-20" VerticalAlignment="Bottom" ManipulationCompleted="OnSoundManipulationChanged" Maximum="100" SmallChange="1" LargeChange="100" Value="75"/> 

會發生什麼是我試圖操縱滑塊,但滑塊只是移動一小步,即使我嘗試移動很長的距離。 ManipulationCompleted事件直到我從滑塊中移除手指時纔會觸發,但它也只是設置較小的值更改。

在我的應用程序中導航一次到另一個頁面後發生此行爲。 如果我重新啓動應用程序,它會再次工作。

回答

0

我找到了解決方案,解決方案由Paul Sinnema發佈,工作正常!

http://forums.create.msdn.com/forums/p/82897/501068.aspx

using System.Windows; 
using System.Windows.Controls; 

namespace ControlClassLibrary 
{ 
public class PSSlider : Slider 
{ 
    public PSSlider() 
    { 
    } 

    public UIElement GestureListenerBug 
    { 
     get { return (UIElement)GetValue(GestureListenerBugProperty); } 
     set { SetValue(GestureListenerBugProperty, value); } 
    } 

    public static readonly DependencyProperty GestureListenerBugProperty = 
     DependencyProperty.Register("GestureListenerBug", typeof(UIElement), typeof(PSSlider), new PropertyMetadata(null)); 

    protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e) 
    { 
     SetHitTestVisibility(false); 

     base.OnMouseEnter(e); 
    } 

    protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e) 
    { 
     SetHitTestVisibility(true); 

     base.OnMouseLeave(e); 
    } 

    private void SetHitTestVisibility(bool visible) 
    { 
     if (GestureListenerBug != null) 
     { 
      GestureListenerBug.IsHitTestVisible = visible; 
     } 
    } 
} 

}

<ct:PSPhoneApplicationPage x:Class="MCRemote.MainPage" 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
         xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
         xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:cv="clr-namespace:MCRemote.Converters" 
         xmlns:ct="clr-namespace:ControlClassLibrary;assembly=ControlClassLibrary" 
         xmlns:co="clr-namespace:MCRemote.Controls" 
         xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
         mc:Ignorable="d" 
         x:Name="Main" 
         SupportedOrientations="Portrait" 
         Orientation="Portrait" 
         shell:SystemTray.IsVisible="True" 
         Loaded="PhoneApplicationPageLoaded" 
         d:DesignHeight="768" 
         d:DesignWidth="480" 
         Foreground="White"> 

...

  <ct:PSSlider x:Name="VolumeSlider" 
         GestureListenerBug="{Binding ElementName=Main}" 
         Maximum="1" 
         Minimum="0" 
         SmallChange="0.01" 
         LargeChange="0.1" 
         ManipulationStarted="SliderManipulationStarted" 
         ManipulationCompleted="SliderManipulationCompleted" 
         Value="{Binding PlaybackInfo.BoundVolume, Mode=TwoWay}" 
         Grid.Column="1" 
         Grid.Row="2" />