【问题标题】:Slider control not resizing correctly when Page Orientation changes页面方向更改时滑块控件无法正确调整大小
【发布时间】:2012-02-23 12:50:09
【问题描述】:

有人在使用 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>

【问题讨论】:

  • 您找到解决问题的方法了吗?我也有同样的问题...
  • @pivotnig - 看看我的回答能否为您解决问题。

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


【解决方案1】:

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

【讨论】:

  • 感谢 Metro Smurf,我会检查一下,然后再发回。 :)
  • 效果很好。谢谢地铁蓝精灵。标记为已回答。
  • 不错!这确实很奇怪。
猜你喜欢
  • 2013-05-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多