2013-10-25 4 views
1

현재 프로그래밍 방식으로 ListBox를 얻으려고합니다. 여러 가지 방법을 찾으려고했지만이 방법을 사용할 수 없습니다.xaml 디자인에서 C# 코드로 변경

<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="PeerList" Margin="10,10,0,10"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
       <TextBlock Text="{Binding DisplayName}" FontSize="{StaticResource PhoneFontSizeMedium}" Margin="40,0,0,0"/> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

나는이 같은 작업이 프로그래밍 방식으로 수행 할 :

여기에 코드의 XAML 부분입니다.

XAML에 익숙한 사람이이 문제를 해결할 수 있도록 도와줍니다. .

enter image description here

답변

1

같은 것입니다.

그렇지 않은 경우에만 동료의 이름을 얻고 싶습니다. 그냥 따라와.

void SearchPeers() 
{ 
    List<string> name = new List<string>(); 
    var peers = await PeerFinder.FindAllPeersAsync(); 
    for(int i=0;i<peers.Count;i++) 
    { 
     string peerName = peers.DisplayName; 
     name.Add(peerName); 
    } 
} 

사용 가능한 피어의 이름이 표시됩니다.

2

당신이, 프로그램이 목록에있는 동료의 이름을 표시 할 HIEP Lê 응답 @ 따라 의미 경우이

ListBox listbox = new ListBox(); 
DataTemplate dataTemplate = new DataTemplate(); 
FrameworkElementFactory elementFactory = new FrameworkElementFactory(typeof(TextBlock)); 
elementFactory .SetBinding(TextBlock.TextProperty, new Binding("DisplayName")); 
dataTemplate.VisualTree = elementFactory; 

listbox.ItemTemplate = dataTemplate ; 
+0

Visual Studio 2012에서 Windows Phone8 용 FrameWorkElementFactory를 사용할 수 없습니다. 특정 기능은 Ultimate 버전에서만 사용 가능합니까? – Ethan

+0

FrameWorkElementFactory는 .NET 3.0에 도입되었으며 모든 버전의 Visual Studio에서 사용할 수 있습니다. – Stewbob

+0

@Stewbob 현재 Visual Studio 2012 Express Edition을 사용 중입니다. 나는 FrameworkElementFactory를 타이핑 해 보았다. 하지만 내 편집자에게는 그 옵션이 표시되지 않습니다. 이 Scnario 이미지는 위의 질문 자체에서 편집했습니다. – Ethan