gpt4 book ai didi

c# - 当页面方向更改时, slider 控件无法正确调整大小

转载 作者:行者123 更新时间:2023-11-30 17:13:49 24 4
gpt4 key购买 nike

有没有人在使用 Windows Phone 7.1 时遇到过这个问题?

我有一个简单的页面,顶部有一个 slider 控件,已拉伸(stretch)到全宽。该页面支持方向更改。

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

我看到一个 slider ,但按钮不在屏幕上,如果我点击 slider 中的任意位置以移动栏按钮,则需要尝试几次。这似乎是因为 slider 没有正确调整大小。这似乎只有在 slider 值最大时才会发生。

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

试一试,在横向模式下运行它,将 slider 一直向右移动,然后更改为纵向模式并注意 slider 栏末端现在不可见。

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

最佳答案

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

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

关于c# - 当页面方向更改时, slider 控件无法正确调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9413420/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com