c# - CustomMessageBox 中的列表框总是向上滚动

标签 c# windows windows-phone-8 listbox messagebox

我有一个列表框的奇怪问题,它被放置在一个自定义消息框中。

问题:您无法向下滚动列表,因为“拖动手势”向上与向下的效果相同。所以我唯一得到的就是当您位于列表顶部时的响应动画。

我做了一个小样本:

<!--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 Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock 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">

        <Button Background="Bisque" Content="Click Me" Click="Button_Click"></Button>

    </Grid>
</Grid>

public partial class MainPage : PhoneApplicationPage
{
    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var source = new string[200];

        for (int i = 0; i < source.Length; i++)
        {
            source[i] = i.ToString();
        }

        var dialog = new CustomMessageBox()
        {
            Content = new ListBox(){ItemsSource = source},
            RightButtonContent = "Cancel",
            LeftButtonContent = "Store",
            VerticalContentAlignment = VerticalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Center,
            Background = new SolidColorBrush(Colors.Black),
            HorizontalContentAlignment = HorizontalAlignment.Center,
            HorizontalAlignment = HorizontalAlignment.Center
        };

        dialog.Show();
    }
}

如果你想下载它,这里是链接: https://onedrive.live.com/redir?resid=6B27FD720F1FB58D!15988&authkey=!ACG5krcfzsoBxA8&ithint=folder%2csln

有谁知道出了什么问题吗? 感谢您的帮助。

最佳答案

有一个简单的修复方法。将 Height 添加到 ListBox。像这样。

var dialog = new CustomMessageBox()
{
    Content = new ListBox(){ItemsSource = source, Height = 800},
    RightButtonContent = "Cancel",
    LeftButtonContent = "Store",
    VerticalContentAlignment = VerticalAlignment.Top, // Change to Top
    VerticalAlignment = VerticalAlignment.Top, // Change to Top
    Background = new SolidColorBrush(Colors.Black),
    HorizontalContentAlignment = HorizontalAlignment.Center,
    HorizontalAlignment = HorizontalAlignment.Center
};

VerticalContentAlignmentVerticalAlignment 更改为顶部,这样当您将高度值设置为小于 800 时,内容将对齐到顶部。

关于c# - CustomMessageBox 中的列表框总是向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308490/

相关文章:

python - Windows:如何配置多个版本的Python以协同工作?

jquery-mobile - 在 Xamarin 解决方案中使用 jQuery Mobile 是否可行?

visual-studio-2012 - 运行 Windows Phone 模拟器的 Hyper-V 的替代方案

c# - ClickOnce 应用程序抛出错误 "..requires assembly MySql.Data Version 6.5.4.0 be installed in the Global Assembly Cache (GAC) first."

c# - 对列表和打印值的反射(reflection)

c# - 创建 X509Certificate2 时阻止创建文件?

c# - MassTransit 使用元数据创建请求

windows - 如何避免 GetFileAttributes 中的网络停顿?

python - Cython 静态链接与 python 运行时?

c# - Windows Phone 8.1 滚动查看器不滚动