2013-07-30 3 views
0

내가 선택하고 사용자의 UI에 LongListSelector의 항목을 조작 할 필요가있다. 코드 샘플에서 (this) 예제를 볼 수 있지만 제대로 이해하지 못했습니다.프로그래밍

에 속하는 StackPanel의 배경을 변경하고 TextBlock을 프로그래밍 방식으로 코드 뒤에 추가 할 수 있습니까?

<phone:LongListSelector.ItemTemplate> 
    <DataTemplate> 
     <StackPanel Orientation="Horizontal"> 

     </StackPanel> 
    </DataTemplate> 
</phone:LongListSelector.ItemTemplate> 

답변

0

나는 창문을 휴대 전화 개발에서 새로운 이후 정확하게 귀하의 질문을 이해 여부 모르겠어요. 다음은 스택 패널의 배경을 변경하고 프로그래밍 방식으로 텍스트 블록을 추가하는 코드입니다.

enter code here 

    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
     // change the background of stackpanel 
     StackPanel st = new StackPanel(); 
     SolidColorBrush mysolidbrush = new SolidColorBrush(); 
     mysolidbrush.Color = Color.FromArgb(255, 100,100,10); // RGB color 
     st.Background = mysolidbrush; 

     // Adding textblock to the stackpanel 
     TextBlock txtblk = new TextBlock(); 
     st.Children.Add(txtblk); 

    } 

보다도, B

1

당신이 StackPanel에

private void lls_SelectionChanged(object sender, SelectionChangedEventArgs e) { 
    var spList = new List<StackPanel>(); 
    GetItemsRecursive<StackPanel>(lls, ref spList); 

    // Selected. 
    if (e.AddedItems.Count > 0 && e.AddedItems[0] != null) { 
    foreach (var sp in spList) { 
     if (e.AddedItems[0].Equals(sp.DataContext)) { 
     sp.Background = new SolidColorBrush(Colors.Green); 
     sp.Children.Add(new TextBlock { Text = "Hello" }); 
     } 
    } 
    } 

    // Unselected. 
    if (e.RemovedItems.Count > 0 && e.RemovedItems[0] != null) { 
    foreach (var sp in spList) { 
     if (e.RemovedItems[0].Equals(sp.DataContext)) { 
     sp.Background = (SolidColorBrush)Resources["PhoneBackgroundBrush"]; 
     sp.Children.RemoveAt(sp.Children.Count - 1); 
     } 
    } 
    } 
} 
와 함께 작업을 링크 된 샘플을 만들려면