2012-02-07 2 views
1

슬라이더 컨트롤을 사용하려고합니다. 그것은 단지 간단한 제어입니다. 멋진 일은 없어. 그러나 나는 혼란스런 문제에 봉착한다.wp7 슬라이더가 달려 있습니다.

컨트롤을 테스트 페이지 (아무것도 표시하지 않음)에 놓고 앱이 시작된 직후에 탐색하면 완벽하게 슬라이드 할 수 있습니다. 하지만 먼저 다른 페이지로 이동 한 다음 테스트 페이지로 이동하면 나는 아주 이상한 행동을 취한다. 슬라이더 컨트롤이 단계적으로 이동합니다. 마치 전화가 끊어 지거나 포커스를 잃는 것처럼 보입니다.

저는 wp7.1을 사용하고 있으며 에뮬레이터와 전화에서 테스트했습니다. 둘 다 나에게 같은 결과를 준다. 이 문제를 어디서부터 시작해야할지조차 모르겠지만 슬라이더가 필요하고 부드럽게 움직이게해야합니다.

아이디어가 있으십니까?

<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> 
여기

에뮬레이터의 행동에 그것의 비디오에 대한 링크입니다 :

는 XAML을 포함하도록 수정. https://vimeo.com/36428677

+0

당신이 컨트롤에 아무것도 확실합니까? 피벗 컨트롤에 슬라이더가있는 경우이 문제가 발생합니다. – MyKuLLSKI

+1

XAML을 보여줍니다! –

답변

0

그래서 슬라이더가 왜 그런 식으로 스틱을 붙일 지 모르겠지만 계속 앞으로 나아갈 수 있도록 내 자신의 슬라이더를 만들었습니다. 바라건대이 코드가 다른 사람을 돕기를 바랍니다.

XAML :

<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); 
    } 

} 

}

관련 문제