如何修复ListView数据绑定以显示添加的项目?

时间:2015-04-11 10:28:24

标签: c# xaml windows-phone-8.1

我正在尝试ListViewItemTemplate进行CheckBoxTextBlock控制并将数据绑定到它。但是,列表不会显示添加的项目。

这是我的XAML代码:

 <ListView x:Name="WarrantyCategory_ListView" HorizontalAlignment="Stretch"  Grid.Row="3" VerticalAlignment="Center" SelectionMode="Single" Header="Category:" FontSize="16" Foreground="#FFC7C7C7" Margin="10,0" ItemsSource="{Binding WarrantyCategories}" >
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Vertical">
                    <CheckBox x:Name="Description_CheckBox" IsChecked="{Binding IsChecked, Mode=TwoWay}"/>
                    <TextBlock x:Name="DescriptionItem_TextBlock"     Text="{Binding Category, Mode=TwoWay}" />
                </StackPanel>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

这是我的WarrantyCategory类:

public class WarrantyCategory
{
    public bool IsChecked { get; set; }
    public string Category { get; set; }

    public WarrantyCategory(bool isChecked, string category)
    {
        IsChecked = isChecked;
        Category = category;
    }
}

和我的页面代码背后:

public AddWarrantyDescriptionPage()
{
    this.InitializeComponent();
    DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
    InitializeCategoryList();
}

private void InitializeCategoryList()
{
    WarrantyCategories.Add(new WarrantyCategory(false, "Computers"));
    WarrantyCategories.Add(new WarrantyCategory(false, "Mobile"));
    WarrantyCategories.Add(new WarrantyCategory(false, "Music"));
    WarrantyCategories.Add(new WarrantyCategory(false, "Video"));

}

0 个答案:

没有答案