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



有人在Windows Phone 7.1中遇到过这个问题吗?

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

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

我看到一个滑块,但按钮不在屏幕上,如果我点击滑块中的任何位置来移动条形按钮,需要几次尝试。出现这种情况似乎是因为滑块没有正确调整大小。只有当滑块值处于最大时,才会出现这种情况

其他人看到这个问题了吗?模拟器和我的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>

我可以重现这个问题,即使滑块按钮小于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();
}

最新更新