Silverlight wp7滑块挂起

Silverlight wp7滑块挂起,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我正在尝试使用滑块控制。这只是简单的控制。没什么特别的。但我遇到了一个让我困惑的问题 如果我将控件放在一个测试页面上(空白,没有其他内容),并在应用程序启动后立即导航到它,我就可以完美地滑动它。但是如果我先导航到另一个页面,然后再导航到测试页面。我有一种很奇怪的行为。滑块控件按步移动。它似乎挂断了或正在失去焦点 我使用的是wp7.1,我已经在模拟器和手机上进行了测试。两者都给我相同的结果。我甚至不知道从哪里开始解决这个问题,但我确实需要一个滑块,让它平稳地移动 有什么想法吗 修订为包括xaml:

我正在尝试使用滑块控制。这只是简单的控制。没什么特别的。但我遇到了一个让我困惑的问题

如果我将控件放在一个测试页面上(空白,没有其他内容),并在应用程序启动后立即导航到它,我就可以完美地滑动它。但是如果我先导航到另一个页面,然后再导航到测试页面。我有一种很奇怪的行为。滑块控件按步移动。它似乎挂断了或正在失去焦点

我使用的是wp7.1,我已经在模拟器和手机上进行了测试。两者都给我相同的结果。我甚至不知道从哪里开始解决这个问题,但我确实需要一个滑块,让它平稳地移动

有什么想法吗

修订为包括xaml:

<phone:PhoneApplicationPage 
x:Class="WP7ListBoxSelectedItemStyle.TestPage"
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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
xmlns:local="clr-namespace:WP7ListBoxSelectedItemStyle"
xmlns:my="clr-namespace:colordata_controls;assembly=colordata_controls"
shell:SystemTray.IsVisible="True" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="IPO" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="Test" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="8,17,16,-17">
        <Slider Height="84" HorizontalAlignment="Left" Margin="10,10,0,0" Name="slider1" VerticalAlignment="Top" Width="460" />
    </Grid>
</Grid>


下面是一个链接,指向emulator中正在运行的视频

所以,我仍然不知道为什么滑块会这样,但为了继续前进,我创建了自己的滑块。希望这段代码能帮助其他人

xaml:


代码:

命名空间控件{
公共部分类pSlider:UserControl{
公共活动路线已更改,但未更改经销商价值;
公共静态只读DependencyProperty MaxProperty=
DependencyProperty.Register(“最大值”、typeof(双精度)、typeof(pSlider)、新PropertyMetadata(100.0));
公共双倍最大值{
获取{return(double)GetValue(MaxProperty);}
set{SetValue(MaxProperty,value);}
}
公共静态只读从属属性MinProperty=
DependencyProperty.Register(“最小值”、typeof(双精度)、typeof(pSlider)、new PropertyMetadata(0.0));
公共双最小值{
获取{return(double)GetValue(MinProperty);}
set{SetValue(MinProperty,value);}
}
公共静态只读从属属性ValueProperty=
DependencyProperty.Register(“Value”、typeof(double)、typeof(pSlider)、新PropertyMetadata(50.0));
公共双重价值{
获取{return(double)GetValue(ValueProperty);}
set{SetValue(ValueProperty,value);}
}
公共pSlider(){
初始化组件();
已加载+=新的路由EventHandler(pSlider_已加载);
}
已加载无效pSlider_(对象发送器,路由目标e){
如果(值>最大值)
值=最大值;
否则如果(值<最小值)
值=最小值;
双最小值=0;
最大加倍=g_集装箱实际高度;
升降器高度=值/(最大值-最小值)*(最大值-最小值);
}
私人点位;
私有无效布局root\u MouseMove(对象发送方,MouseEventArgs e){
点newPosition=e.GetPosition((UIElement)发送器);
双三角=newPosition.Y-Position.Y;
双温度=r_升降器高度-增量;
如果(温度>集装箱实际高度)
r_升降机高度=g_集装箱实际高度;
否则如果(温度<0)
r_升降机高度=0;
其他的
升降器高度=温度;
双最小值=0;
最大加倍=g_集装箱实际高度;
值=升降器高度/(最大-最小)*(最大-最小);
值=数学地板(值);
RoutedEventHandler=ValueChanged;
if(处理程序!=null)
处理者(本,e);
位置=e.GetPosition((UIElement)发送器);
}
私有无效布局root\u MouseLeftButtonDown(对象发送器,MouseButtonEventArgs e){
位置=e.GetPosition((UIElement)发送器);
}
}

}

您确定控件中没有任何内容吗?如果轴控件中有滑块,则会发生此行为
<UserControl 
x:Name="userControl" 
x:Class="controls.pSlider"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="76" d:DesignHeight="400" Background="Gray" Foreground="White">

<Grid x:Name="LayoutRoot" Background="Transparent" MouseMove="LayoutRoot_MouseMove" MouseLeftButtonDown="LayoutRoot_MouseLeftButtonDown">
    <Grid.RowDefinitions>
        <RowDefinition Height="10"/>
        <RowDefinition/>
        <RowDefinition Height="10"/>
    </Grid.RowDefinitions>
    <Rectangle x:Name="colorBar" Margin="20,6" Width="10" Fill="{Binding Background, ElementName=userControl}" Grid.Row="1"/>
    <Grid x:Name="g_container" Grid.Row="1" Margin="0,1,0,13">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="0"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid x:Name="g_thumb" Height="0" VerticalAlignment="Top" Grid.Row="1">
            <Canvas Height="0" VerticalAlignment="Top">
                <Path Data="M0,0 L1,0 L1.2,0.5 L1,1 L0,1 z" Margin="0" Stretch="Fill" UseLayoutRounding="False" Width="33" RenderTransformOrigin="0.5,0.5" StrokeThickness="0" Fill="{Binding Foreground, ElementName=userControl}" Height="12" d:LayoutOverrides="VerticalAlignment"/>
                <Path Data="M0.3,0.5 L0.5,0 L1.5,0 L1.5,1 L0.5,1 z" Margin="0" Stretch="Fill" UseLayoutRounding="False" Width="33" RenderTransformOrigin="0.5,0.5" StrokeThickness="0" Fill="{Binding Foreground, ElementName=userControl}" Height="12" Canvas.Left="43" d:LayoutOverrides="VerticalAlignment"/>
            </Canvas>
        </Grid>
        <Rectangle x:Name="r_lifter" Margin="0" Grid.Row="2" Height="188" StrokeThickness="0"/>
    </Grid>
</Grid>
namespace controls {
public partial class pSlider : UserControl {

    public event RoutedEventHandler ValueChanged;

    public static readonly DependencyProperty MaxProperty =
    DependencyProperty.Register("Maximum", typeof(double), typeof(pSlider), new PropertyMetadata(100.0));

    public double Maximum {
        get { return (double)GetValue(MaxProperty); }
        set { SetValue(MaxProperty, value); }
    }

    public static readonly DependencyProperty MinProperty =
    DependencyProperty.Register("Minimum", typeof(double), typeof(pSlider), new PropertyMetadata(0.0));

    public double Minimum {
        get { return (double)GetValue(MinProperty); }
        set { SetValue(MinProperty, value); }
    }

    public static readonly DependencyProperty ValueProperty =
    DependencyProperty.Register("Value", typeof(double), typeof(pSlider), new PropertyMetadata(50.0));

    public double Value {
        get { return (double)GetValue(ValueProperty); }
        set { SetValue(ValueProperty, value); }
    }

    public pSlider() {
        InitializeComponent();
        Loaded += new RoutedEventHandler(pSlider_Loaded);
    }

    void pSlider_Loaded(object sender, RoutedEventArgs e) {

        if (Value > Maximum)
            Value = Maximum;
        else if (Value < Minimum)
            Value = Minimum;

        double min = 0;
        double max = g_container.ActualHeight;

        r_lifter.Height = Value / (Maximum - Minimum) * (max - min);

    }

    private Point Position;

    private void LayoutRoot_MouseMove(object sender, MouseEventArgs e) {
        Point newPosition = e.GetPosition((UIElement)sender);

        double delta = newPosition.Y - Position.Y;
        double temp = r_lifter.Height - delta;

        if (temp > g_container.ActualHeight)
            r_lifter.Height = g_container.ActualHeight;
        else if (temp < 0)
            r_lifter.Height = 0;
        else
            r_lifter.Height = temp;

        double min = 0;
        double max = g_container.ActualHeight;

        Value = r_lifter.Height / (max - min) * (Maximum - Minimum);
        Value = Math.Floor(Value);
        RoutedEventHandler handler = ValueChanged;
        if (handler != null)
            handler(this, e);


        Position = e.GetPosition((UIElement)sender);
    }

    private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
        Position = e.GetPosition((UIElement)sender);
    }

}