【发布时间】:2025-12-29 02:15:11
【问题描述】:
我正在尝试在我的应用程序 Windows Phone 中使用模式 MVVM。但是我在绑定列表框内的 CheckBox 时遇到了问题。
这是我的 .xaml
<ListBox x:Name="LstbTagsFavoris" SelectionChanged="favoris_SelectionChanged" Margin="10,10,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Foreground="#555" Background="Red" Loaded="CheckBox_Loaded" Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" Content="{Binding Categories}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的视图模型
public class CategorieViewModel
{
private List<string> _Categories = new List<string>();
public List<string> Categories
{
get
{
return _Categories;
}
set
{
_Categories = value;
}
}
public void GetCategories()
{
Categories = GlobalVar._GlobalItem.SelectMany(a => a.tags)
.OrderBy(t => t)
.Distinct()
.ToList();
}
在我的 xaml.cs 中:
CategorieViewModel c = new CategorieViewModel();
c.GetCategories();
this.DataContext = c;
但是没用
【问题讨论】:
标签: c# xaml windows-phone-8 mvvm listbox