2010-03-16 96 views
1

我的代碼列表框顯示字符串垂直

Add("STRING"); 
public void Add(string menu) 
    {     
DataContext = menu.ToString(); 
} 

列表框

的XAML代碼
<ListBox x:Name="menubox" ItemsSource='{Binding}' Margin="0,5,0,0" Height="244" Width="240" Background="Silver" BorderThickness="0" >     
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Foreground="Blue" FontWeight="Bold" Text="{Binding}"/> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

但打印像 小號 Ť ř 我 Ñ ģ vertically.Each信作爲一個項目。 如何打印它作爲燎字符串謊言「STRING」

回答

1

您指定爲您的列表框中的ItemSource是你的字符串,就意味着你的字符串中的每個項目(人物)將是它自己的ListBoxItem的。因此,你的字符串會是縱向的,你看到的如果你想有一個列表框有一個項目在它標記爲「字符串」,請嘗試以下操作:

代碼: 列表strArray =新名單(); //類級別的變量

public void Add(string menu) 
    { 
     strArray.Add(menu); 
     DataContext = strArray; 
    } 

這應該會給你'String'作爲你的listboxitem。

+0

當我使用它時,它顯示錯誤,因爲缺少組件。 什麼是包含此列表的程序集() – Anu 2010-03-17 04:00:34

+0

您可以使用System.Collections.Generic作爲列表,即列表 Queso 2010-03-17 11:49:53