滚动Usercontrol

时间:2011-02-01 13:24:11

标签: windows-phone-7

我开发了一个用户控件,它有ListBox。当我们滚动时,它不会发生在我身上你能告诉我它会出现什么问题吗?

我有以下项目,

1.Panorama  在侧控件中:PanoramaItem我已经创建了usecontrol的实例

<controls:PanoramaItem Header ="Header">
    <Grid>
      <views:MyUserControlView DataContext="{Binding MyViewModel}" />
    </Grid>
</controls:PanoramaItem>

2.MyUserControlView

<UserControl x:Class="UI.Views.RecentFileView"
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"
xmlns:utility="clr-namespace:UI.CommandBehaviours" 

mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="364" d:DesignWidth="245">

<Grid x:Name="LayoutRoot" Height="360">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <ScrollViewer VerticalScrollBarVisibility="Auto">
        <ListBox x:Name="RecentFilesListBox" Grid.Row="0" ItemsSource="{Binding RecentFiles}" 
                 utility:CommandService.Command="{Binding ToFileViewCommand}" utility:CommandService.CommandParameter="{Binding SelectedItem, ElementName=RecentFilesListBox}" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                    <Image x:Name="ThumbnailImage" Source="{Binding Path=Thumbnail}" Height="43" Width="43" VerticalAlignment="Top" Margin="10,0,20,0"/>
                        <StackPanel>
                            <TextBlock x:Name="FileNameTextBlock" Text="{Binding  Path=FileName, Mode=OneWay}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                            <TextBlock x:Name="FileserverNameTextBlock" Text="{Binding Path=FileServerName}" Style="{StaticResource PhoneTextSubtleStyle}"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>
</Grid>

当我滚动它不适合我..

2 个答案:

答案 0 :(得分:2)

假设您的意思是垂直滚动,那么您显示的结构应该可以正常工作 - 尽管我有点担心<ListBox>

<UserControl>的位置

以下两件事应该有效:

选项1:

<Panorama>
<PanoramaItem>
<MyUserControl>
</PanoramaItem>
</Panorama>

MyUserControl在哪里:

<UserControl>
<ScrollViewer>
<StackPanel>
... lots of <TextBlock>s
</StackPanel>
</ScrollViewer>
</UserControl>

...或

选项2。

<Panorama>
<PanoramaItem>
<MyUserControl>
</PanoramaItem>
</Panorama>

MyUserControl在哪里:

<UserControl>
<ListBox>
... lots of "items" possibly created inside a <DataTemplate>
<ListBox>
</UserControl>

如果您想在ScrollViewer中放置一个项目列表,那么最好使用ItemsControl。

答案 1 :(得分:1)

您为usercontrol发布的XAML无效(它包含额外的</StackPanel>),并且网格数量超出您的需要。

试试这个:

<ListBox x:Name="MyListBox" ItemsSource="{Binding MyProperty}">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        <Image x:Name="MyImage" Source="{Binding MyImageSource}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <StackPanel>
          <TextBlock x:Name="Label" Text="{Binding MyLabel}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
          <StackPanel Orientation="Horizontal">
            <TextBlock x:Name="ReadOnlyTextBlock" Text="{Binding MyStatus}" Style="{StaticResource PhoneTextSubtleStyle}" />
            <TextBlock x:Name="PaidTextBlock" Text="{Binding MyPurchase}" Style="{StaticResource PhoneTextSubtleStyle}" Foreground="Blue"/>
          </StackPanel>
        </StackPanel>
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>