2012-11-28 2 views
1

흥미 롭습니다. 한 요소에서 일부 컨트롤 (이미지, 2-3 텍스트 상자)을 그룹화 한 다음이 요소 그룹을 목록 상자에서 푸시 할 수 있습니까? 나는 Windwos 전화 7목록 상자의 컨트롤

각 뉴스 이미지, 텍스트가

, 그리고 몇몇 다른 메타 데이터에 러시아어 소셜 네트워크 명 Vkontakte의 뉴스 리더를 만들기 위해 노력하고있어. 그래서이 모든 정보를 하나의 컨트롤에 그룹화하고 listbox에서 사용하려고합니다. gridbox (이미지와 두 개의 텍스트 상자가있는)를 listbox로 푸시하기 위해 tryied했지만 XamlParseException이 발생합니다. 또한 텍스트 상자 및 이미지의 내용을 코드에서 가져와야합니다. 사용할 수있는 격자에서

<Grid.Resources> 
    <src:Customers x:Key="customers"/> 
</Grid.Resources> 
+0

모델 (데이터)의 모습은 어떻습니까? 그것은 2' strings'과'Image'입니까? – Blachshma

+0

나는 특성이있는 뉴스를 가지고있다 : string SoourseId, string Text, int Comments, int Likes, PhotoAttachment의 목록 photoAttachment의 목록 VideoAttachment videoAttachments의 목록. 각 모델에는 SourseId 용 txtbox, SourseId의 사진 용 이미지, 텍스트 용 txtbox, 좋아요 및 댓글 용 txtbox가 있습니다. – eg01st

+0

마찬가지로, 뉴스는 사진을 동적으로 카운트 할 수 있지만 지금은이 문제를 해결해야합니다 – eg01st

답변

1

모델의

  • 모음 (ObservableCollection<T> 권장) (News을 당신이 경우에) : 여기 당신이 필요합니다.
  • ListBox
  • DataTemplate

예 :

XAML :

<ListBox Name="ListBox1"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Grid> 
       ... 
       <Image Source="{Binding ImagePropertyInModel}" ... /> 
       <TextBlock Text="{Binding TextPropertyInModel}" ... /> 
       ... 
      </Grid> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

코드 뒤에 대신

ListBox1.ItemsSource = <collection of models>; 

<Grid> f를 <DataTemplate>에서 당신이 사용할 수있는 Custom Control (Templated Control) 또는 이미 수 User Control.

+0

흠 ... 방금 시도했는데 몇 가지 문제가 있습니다 ( – eg01st

0

사용하려는 컨트롤로 UserControl을 만들 수 있습니다. 귀하의 목록 상자를 사용하면 그런 짓을 : 당신의 UserControl의 뉴스 속성에 당신이 뉴스의 ObservableCollection에 사용할 수 및 DataContext="{Binding}" 통해 바인딩 할 수 있습니다 목록 상자의 ItemsSource로

<ListBox ItemsSource="{Binding Path=YourItemsSource}"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
     <my:MyUserControl DataContext="{Binding}"/> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

, 예를 들면 :

<UserControl...> 
    <Image Source="{Binding Path=photoAttachment}"/> 
</UserControl>