如何从列表中创建列表框

时间:2014-07-18 10:33:26

标签: c# xaml windows-phone-8 mvvm listbox

当项目来源是列表时,如何将项目添加到列表框。

XAML:

<ListBox Grid.Row="2" HorizontalAlignment="Stretch" ItemsSource="{Binding Source={StaticResource viewModel}, Path=CultureEvents}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Source={StaticResource viewModel}, Path=ItemTitle}" Height="30" HorizontalAlignment="Left" Margin="116,364,0,0" VerticalAlignment="Top" Width="334" Foreground="White" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

在viewmodel中我有列表:

public List<CultureEvent> CultureEvents { get; set; }

财产:

public string ItemTitle
    {
        get
        {
            return ?;
        }
        set
        {
            ? = value;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemTitle"));
        }
    }

但我不知道该把什么投入财产。

1 个答案:

答案 0 :(得分:0)

private string _itemTitle
public string ItemTitle
    {
        get
        {
            return _itemTitle;
        }
        set
        {
            _itemTitle = value;
            OnPropertyChanged(new PropertyChangedEventArgs("ItemTitle"));
        }

你会生成像这样的列表,

 CultureEvents = new List<CultureEvent>();
 CultureEvents.Add(new CultureEvent{Title = "Yourvalue"} );