tags:

views:

20

answers:

1

My code

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

XAML code of Listbox

<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>

But it print like S T R I N G vertically.Each letter as one item. How can i print it as singe String lie 'STRING"

+1  A: 

You are specifying the itemsource for your listbox to be your string, that means each item (character) within your string will be it's own listboxitem. Therefore you string will be vertical as you are seeing. If you want a listbox with one item in it labeled 'String', try the following:

code: List strArray = new List(); //class level variable

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

That should give you 'String' as your listboxitem.

Queso
Wheni use this,it shows error as missing assembly.Whats the assembly to include for this List()
Anu
You can use System.Collections.Generic for a list, i.e. List<String>
Queso