页面方向更改时,滑块控件未正确调整大小

时间:2012-02-23 12:50:10

标签: c# windows-phone-7 xaml windows-phone-7.1

有没有人遇到过Windows Phone 7.1的问题?

我有一个简单的页面,顶部的滑块控件拉伸到全宽。该页面支持方向更改。

如果您运行应用程序并以纵向模式启动,请将滑块放在栏的中间。现在改变方向,使您处于景观模式。现在将滑块完全向右移动(最大值)。现在回到肖像 - 你看到了什么?

我看到一个滑块,但按钮不在屏幕上,如果我点按滑块中的任意位置移动条形按钮,则需要几次尝试。这似乎正在发生,因为滑块没有正确调整大小。如果滑块值为最大值,则似乎只会发生这种情况。

还有其他人看过这个问题吗?模拟器和我的HTC Mozart设备上的问题是一样的。

尝试此操作,在横向模式下运行,将滑块一直向右移动,然后更改为纵向模式,注意滑块栏末端现在不可见。

<phone:PhoneApplicationPage 
x:Class="SliderRedrawPageOrientation.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: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="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--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="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Slider HorizontalAlignment="Stretch"></Slider>
    </Grid>
</Grid>

1 个答案:

答案 0 :(得分:2)

我可以重现此问题,即使滑块按钮小于MaxValue也会出现此问题。这是一个使用BackgroundWorker和快速小睡的解决方案;有点黑客,但确实解决了这个问题:

public MainPage()
{
    InitializeComponent();

    this.OrientationChanged += OnOrientationChanged;
}

private void OnOrientationChanged( object sender, OrientationChangedEventArgs e )
{
    double val = MySlider.Value;
    MySlider.Value = 0;

    var bw = new BackgroundWorker();
    bw.DoWork += ( _, __ ) => Thread.Sleep( 100 );
    bw.RunWorkerCompleted += ( _, __ ) => Dispatcher.BeginInvoke( () => MySlider.Value = val );
    bw.RunWorkerAsync();
}