0

我在 MainPage.xaml 上使用了一个列表框。通过使用鼠标上下移动,我可以看到内容消失并显示在 Windows Phone 模拟器屏幕上。松开鼠标后,内容将从第一项开始。假设我想选择列表框中的最后一项。如何保留屏幕上的最后一项?希望你能帮助我或给我一个例子或一个想法来解决这个问题。提前致谢。

编辑:

有我的用户控制:

<UserControl x:Class="CMSPhoneApp.QueueListControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"
xmlns:local="clr-namespace:CMSPhoneApp"  >

<UserControl.Resources>       
    <local:VisibilityConverter x:Key="VisibilityConverter"/>
    <local:ColumSpanConverter x:Key="ColumSpanConverter"/>        
</UserControl.Resources>


<Grid x:Name="LayoutRoot"  Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">       
            <ListBox x:Name="lst" HorizontalAlignment="Left" Margin="6,6,0,0"   VerticalAlignment="Top" Width="400"    
                  ItemsSource="{Binding Path=MyQueue}"  
                      SelectedItem="{Binding Path=CurrentQueue, Mode=TwoWay}"  >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border BorderThickness="1,1,1,1" BorderBrush="Blue">
                            <Grid Width="auto" HorizontalAlignment="Stretch" >                                  
                                    <Grid.RowDefinitions>                                          
                                    <RowDefinition Height="auto"/>
                                </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="35" />
                                        <ColumnDefinition Width="250"/>
                                        <ColumnDefinition Width="125" />
                                    </Grid.ColumnDefinitions>
                                    <Image Source="{Binding Type}" Grid.Row="0" Grid.Column="0"/>
                                    <TextBlock  Grid.Row="0" Grid.Column="1"  Grid.ColumnSpan= "{Binding isSpan, Converter={StaticResource ColumSpanConverter}}" Text="{Binding summary}" TextWrapping="Wrap"
                                             Style="{StaticResource PhoneTextAccentStyle}"  />
                                    <Button x:Name="btnAction" Grid.Row="0" Grid.Column="3" ClickMode="Press" Click="btnAction_Click" Style="{StaticResource ButtonStyle1}"
                                            Visibility="{Binding isVisibility, Converter={StaticResource VisibilityConverter}}"
                                         Tag="{Binding callNumber}">

                                        <Button.Content>
                                            <TextBlock Width="85" Height="70" Text="{Binding ActionCaption}" 
                                                       Style="{StaticResource LabelStyle_20}"     />
                                        </Button.Content>
                                    </Button>

                                </Grid>
                                </Border>
                    </DataTemplate>                    

                </ListBox.ItemTemplate>
            </ListBox>

    </Grid>
</Grid>

xaml 页面使用上述用户控件。

   <phone:PhoneApplicationPage xmlns:my="clr-namespace:CMSPhoneApp"  
x:Class="CMSPhoneApp.TestPage"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
xmlns:local="clr-namespace:CMSPhoneApp"
  xmlns:toolkit="clr- namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
  >

<phone:PhoneApplicationPage.Resources>

    <local:QueueItemViewModel x:Key="TestViewModel"/>
    <DataTemplate x:Name="PickerItemTemplate">
        <StackPanel Orientation="Horizontal" >
            <TextBlock Text="{Binding city}" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" />
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Name="PickerFullModeItemTemplate">
        <StackPanel Orientation="Horizontal" >
            <TextBlock Text="{Binding city}" Margin="16 0 0 0" FontSize="24" FontFamily="{StaticResource PhoneFontFamilyLight}" />                        
        </StackPanel>
    </DataTemplate>


</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{StaticResource TestViewModel}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>           
    </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="Test page" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <StackPanel x:Name="City" Grid.Row="1" Margin="12,0,12,0"  Orientation="Horizontal">
        <toolkit:ListPicker   x:Name="listPicker" ItemTemplate="{StaticResource PickerItemTemplate}"  
              Header="Location"   CacheMode="BitmapCache" Width="194" 
                        SelectedItem="{Binding city}"        />

    </StackPanel>
    <!--ContentPanel - place additional content here-->       
        <my:QueueListControl x:Name="lst" Grid.Row="2"/>     
    <StackPanel Grid.Row="3" Orientation="Horizontal" >
        <Button x:Name="btnQueue" Style="{StaticResource ButtonStyle1}" Content="Queue"/>
        <Button x:Name="btnRefresh" Style="{StaticResource ButtonStyle1}" Content="Refresh"/>
        </StackPanel>

</Grid>

获取GetResponseStream后设置itemSource的代码:

 Dispatcher.BeginInvoke(new Action(() => lst.lst.ItemsSource = ar.cmsQueue));   
4

2 回答 2

1

你在这。您没有设置列表框的高度,因此它从其父级获取其高度,即自动(这意味着列表框的高度没有边界)。因此,通过按住鼠标,您可以滚动到任何项目,但不能停在特定项目。将高度固定到 ListBox 400 左右,然后检查。希望这可以解决您的问题

于 2012-08-24T15:18:04.333 回答
0

您是否在代码的任何地方做类似的事情?

listbox.ScrollIntoView(0);,其中 listbox 是您的 mainPage.xaml 上的 ListBox 的名称

尽量避免使用这样的代码行。除此之外,如果没有一些代码,我无法理解您的问题的性质。希望能帮助到你

于 2012-08-24T03:39:03.330 回答