2013-12-13 82 views
0

在Web窗體中Repeater有一個事件OnItemDataBound。
Windows Phone應用程序中的ListBox是否有類似的事件?
我試圖開發聊天(消息)的東西,我需要調整StackPanels在不同的側面。
任何想法?Windows phone ListBox是否具有asp:Repeater的OnItemDataBound類似事件?

的XAML

<ListBox Name="TicketReplyListBox" > 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Background="Blue" MaxHeight="200" Width="400" HorizontalAlignment="Left"> 
       <TextBlock Text="{Binding ContentText}" 
        FontSize="18" 
        FontFamily="\Resources\Fonts\sylfaen.ttf#sylfaen" 
        FontWeight="Bold" 
        TextWrapping="Wrap" 
        Margin="6,12,6,6" 
        HorizontalAlignment="Left" 
        VerticalAlignment="Top" /> 
       <TextBlock Text="{Binding Date}" 
        HorizontalAlignment="Right" 
        VerticalAlignment="Top" 
        Margin="6,0,6,6" 
        FontSize="18" 
        FontFamily="Segoe WP SemiLight" /> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

代碼:

public class TicketReplyModel 
{ 
    public int TicketID { get; set; } 
    public string ContentText { get; set; } 
    public bool IsClient { get; set; } 
    public DateTime Date { get; set; } 
} 
Service1Client WCFClient = new ServiceReference1.Service1Client(); 
public ActiveTicketDetail() 
{ 
    InitializeComponent(); 
    WCFClient.GetTicketReplyListCompleted += new EventHandler<GetTicketReplyListCompletedEventArgs>(WCFClient_GetTicketReplyListCompleted); 
    WCFClient.GetTicketReplyListAsync(84); 
} 

void WCFClient_GetTicketReplyListCompleted(object sender, GetTicketReplyListCompletedEventArgs e) 
{ 
    List<TicketReplyModel> TickteReptyList = new List<TicketReplyModel>(); 
    TickteReptyList = e.Result.ToList(); 
    TicketReplyListBox.ItemsSource = TickteReptyList; 
} 

而且在每次迭代我想根據IsClient

+0

沒有,按我的知識,請詳細說明這個問題,以便我們能夠找到解決問題的一種替代 –

回答

0

的值測量解決方案

XAML中的不同側面對準的StackPanel:

<ScrollViewer> 
    <StackPanel x:Name="Tikcetst"> 
    </StackPanel> 
</ScrollViewer> 

代碼:

public ActiveTicketDetail() 
     { 
      InitializeComponent(); 
      WCFClient.GetTicketReplyListCompleted += new EventHandler<GetTicketReplyListCompletedEventArgs>(WCFClient_GetTicketReplyListCompleted); 
      WCFClient.GetTicketReplyListAsync(84); 



     } 

     void WCFClient_GetTicketReplyListCompleted(object sender, GetTicketReplyListCompletedEventArgs e) 
     { 
      List<TicketReplyModel> TickteReptyList = new List<TicketReplyModel>(); 
      TickteReptyList = e.Result.ToList(); 
      TickteReptyList.ForEach(item => 
      { 
       TextBlock txtBl1 = new TextBlock(); 
       txtBl1.Text = item.ContentText; 
       txtBl1.Padding = new Thickness(5); 
       txtBl1.FontSize = 18; 
       TextBlock txtBl2 = new TextBlock(); 
       txtBl2.Text = item.Date.ToShortDateString(); 
       txtBl2.Padding = new Thickness(5);     
       txtBl2.FontSize = 14; 
       txtBl2.HorizontalAlignment = HorizontalAlignment.Right; 
       StackPanel st = new StackPanel(); 
       st.Children.Add(txtBl1); 
       st.Children.Add(txtBl2); 

       st.Width = 400;     
       st.HorizontalAlignment = item.IsClient ? HorizontalAlignment.Right : HorizontalAlignment.Left; 
       st.Margin = new Thickness(5); 
       string fileName = item.IsClient ? "Images/MessagecollorMe.png" : "Images/MessagecollorBank.png"; 
       BitmapImage image = new BitmapImage(new Uri(fileName, UriKind.Relative)); 
       ImageBrush brush = new ImageBrush(); 
       brush.ImageSource = image; 
       st.Background = brush; 
       Tikcetst.Children.Add(st); 
      }); 
     } 
相關問題