C# CustomMessageBox中的Listbox始终向上滚动
我有一个奇怪的列表框问题,它放在custommessagebox中 问题:您无法向下滚动列表,因为“draggesture”向上与向下做相同的事情。因此,我得到的唯一一件事就是当你的动画在列表的顶部时的响应动画 我做了一个小样本:C# CustomMessageBox中的Listbox始终向上滚动,c#,windows,windows-phone-8,listbox,messagebox,C#,Windows,Windows Phone 8,Listbox,Messagebox,我有一个奇怪的列表框问题,它放在custommessagebox中 问题:您无法向下滚动列表,因为“draggesture”向上与向下做相同的事情。因此,我得到的唯一一件事就是当你的动画在列表的顶部时的响应动画 我做了一个小样本: <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Name="LayoutRoot" Background="Transparent">
<!--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部分类主页:PhoneApplicationPage
{
//建造师
公共主页()
{
初始化组件();
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
变量源=新字符串[200];
for(int i=0;i
这是链接,如果你想下载:
有人知道出了什么问题吗?
谢谢您的帮助。有一个简单的解决方案。。将
高度
添加到列表框
。像这样
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
};
将
垂直内容对齐
和垂直对齐
更改为顶部,以便将高度值设置为小于800时,内容与顶部对齐。只需为列表框添加高度,如下所示:
Content=new ListBox(){ItemsSource=source,Height=800}
我不建议设置高度,因为Daniel Z提到,您将失去自适应设计。我管理了一个更好的解决方案,它在不将高度设置为静态值的情况下非常适合我
将CustomMessageBox
的内容放入UserControl
中。假设此控件的xaml
内容如下所示
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
<!-- your listbox and content here -->
</Grid>
通过设置网格的高度,listbox将自动调整其高度以适应。希望能有所帮助。只给出一个固定的高度就解决了问题。无需将垂直对齐更改为顶部。但最好是设置MaxHeight而不是Height。因此,您不会失去自适应设计。Thx很多,从没想过这会是个问题。
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
<!-- your listbox and content here -->
</Grid>
public UserControl1()
{
InitializeComponent();
this.Loaded += UserControl1_Loaded;
}
void UserControl1_Loaded(object sender, RoutedEventArgs e)
{
LayoutRoot.Height = (this.Parent as CustomMessageBox).ActualHeight;
}