2011-08-15 3 views
0

WP7에서 ListBox를 구성하는 방법을 알고 싶습니다. 한 번에 20 개의 항목 만로드하고 "load more"가 있으면 표시하는 바닥 글이 있습니다."load more"옵션을 사용하는 ListBox

사용자가 "더로드"를 누르면 이전에로드 한 데이터를로드하지 않고 목록에서 다른 20 개를로드합니까?

나는 뒤에서 LINQ를 사용하고 있습니다.

다음과 같은 XMAL에 대한 내 코드 :

using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    using (IsolatedStorageFileStream fs = storage.OpenFile(fileName, FileMode.Open)) 
    { 
     XDocument menuIndex = XDocument.Load(fs); 

     var menuIndexList = from query in menuIndex.Descendants("news") 
          orderby (int)query.Element("newsID") descending 
          select new mkmenu 
            {             
             pID = query.Element("newsID").Value, 
             pTitle = query.Element("newsTitle").Value, 
             pDate = query.Element("newspDate").Value, 
             pType = newsType 
            }; 

     newsIndexListBoxEN = menuIndexList.Count(); 
    } 
} 

아이디어 : 다음과 같은

<Grid> 
    <ListBox name="newsIndexListBoxEN"> 
    <ListBoxItem> 
     <DataTemplate> 
     <StackPanel Width="410" Orientation="Horizontal" VerticalAlignment="Top" Margin="0,5,0,5"> 
      <StackPanel Background="DarkBlue" Margin="10,0,0,0" Height="100" Width="100" VerticalAlignment="Top"> 
      <TextBlock Name="columnsTypeTB" Text="{Binding pType}" Margin="0,0,0,0" Foreground="White" FontSize="23" HorizontalAlignment="Center" /> 
      <Image Width="100" Height="100" VerticalAlignment="Top" HorizontalAlignment="Center" Source="Background.png" /> 
      </StackPanel> 
      <StackPanel Width="300" Height="100" Margin="0,0,0,0"> 
      <Path Margin="0,0,0,0" Data="M39,8 L389,8" Fill="DarkBlue" Height="1" Stretch="Fill" Stroke="DarkBlue" UseLayoutRounding="False" Width="400"/> 
      <TextBlock Margin="8,0,0,0" Text="{Binding pTitle}" Tag="{Binding pID}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Width="292" Height="66" /> 
      <TextBlock Margin="8,5,0,0" Text="{Binding pDate}" Tag="{Binding pID}" MouseEnter="NewsViewContent_mouseEnter" Style="{StaticResource PhoneTextSmallStyle}" VerticalAlignment="Bottom" TextWrapping="Wrap" Width="292" /> 
      </StackPanel> 
     </StackPanel> 
     </DataTemplate> 
    </ListBoxItem> 
    </ListBox> 
</Grid> 

C# 코드? 샘플 코드?

답변

4

목록 상자 서식 파일을 편집하여 목록 끝에 "추가로드"단추를 표시 할 수 있습니다. Blend에서 목록 상자를 마우스 오른쪽 버튼으로 클릭하고 템플리트 편집, 사본 편집을 선택하십시오.

ScrollViewer 
    ItemPresenter 

다음 마지막에 버튼을 추가, StackPanel에로 ItemPresenter 랩 : 기본적으로 목록 상자는 다음과 같이 템플릿을이 버튼은 항상의 끝에 표시됩니다

ScrollViewer 
    StackPanel 
     ItemPresenter 
     Button 

리스트 박스. ObservableCollection에 항목을 추가하려면 해당 단추의 Clicked 이벤트를 처리하십시오.

+0

동일한 레벨의 ItemPresenter에 "Button"세트를 가져올 수 없습니다. StackPanel과 항상 같은 레벨입니다. 이 결과를 통해 항상 페이지 상단에 버튼이 표시됩니다. –

+0

감사! 나는 내가 어디에서 잘못했는지 알아낼 수있다! –

2

bind your listbox에서 ObservableCollection까지 가능하며 페이지 (앱)로드에서 처음 20 개 항목을 추가 할 수 있습니다. "load more"를 누른 후 다음 20 개 항목을 가져 와서 컬렉션에 추가하십시오. 항목이 자동으로 목록 상자에 추가됩니다.

+0

첫 번째 링크는 이미 예제가 포함되어 있습니다. –