C# 复选框列表-动态列表C/XAML
我有三张桌子 用户: 偏好: 用户首选项: 如何为保持数据创建视图模型并创建这样的表单C# 复选框列表-动态列表C/XAML,c#,wpf,xaml,C#,Wpf,Xaml,我有三张桌子 用户: 偏好: 用户首选项: 如何为保持数据创建视图模型并创建这样的表单 New User Name |------------| |textbox | |------------| Your Preferences [ ] Preference1 [ ] Preference2 [ ] Preference3 .. [ ] PreferenceN 我相信,应该是这样的: 带C的元代码 // You can realize INotificationChanged
New User
Name
|------------|
|textbox |
|------------|
Your Preferences
[ ] Preference1
[ ] Preference2
[ ] Preference3
..
[ ] PreferenceN
我相信,应该是这样的: 带C的元代码
// You can realize INotificationChanged here too if you need
sealed class Preference
{
public Preference(string name, bool isSelected)
{
Name = name;
IsSelected = isSelected;
}
public string Name { get; private set; }
public bool IsSelected { get; set; }
}
sealed class User : INotificationChanged
{
private ObservaleCollection<Preference> viewPreferences;
public event PropertyChangedEventHandler PropertyChanged;
public User(PreferenceCollection preferences)
{
PreferenceTitle = preferences.Title;
// put info to collection
}
public ObservaleCollection<Preference> Preferences
{
get { return preferences; }
}
// You can remove set if you don't want to set it directly
public UserId { get; set; }
public UserName { get; set; }
public PreferenceTitle { get; private set; }
// Use it to update data in view
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
这只是一个模型的模型。当然,您需要添加验证、保存数据逻辑以及将属性绑定到xaml表单
user_id
preference_id
New User
Name
|------------|
|textbox |
|------------|
Your Preferences
[ ] Preference1
[ ] Preference2
[ ] Preference3
..
[ ] PreferenceN
// You can realize INotificationChanged here too if you need
sealed class Preference
{
public Preference(string name, bool isSelected)
{
Name = name;
IsSelected = isSelected;
}
public string Name { get; private set; }
public bool IsSelected { get; set; }
}
sealed class User : INotificationChanged
{
private ObservaleCollection<Preference> viewPreferences;
public event PropertyChangedEventHandler PropertyChanged;
public User(PreferenceCollection preferences)
{
PreferenceTitle = preferences.Title;
// put info to collection
}
public ObservaleCollection<Preference> Preferences
{
get { return preferences; }
}
// You can remove set if you don't want to set it directly
public UserId { get; set; }
public UserName { get; set; }
public PreferenceTitle { get; private set; }
// Use it to update data in view
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}