我正在尝试根据所选的 ListViewItem 更改项目可见性。基本上,ListView 中的每一列在网格上都有两个项目、一个标签和一个控件(组合框、日期选择器、文本框等)。如果选择 ListViewItem,那么我希望该行中的所有控件都可见,否则标签应该可见。这是在 UserControl 上,而不是在 Window 上,如果这有什么区别的话。
这是我的视图模型
public class DailyServiceLogsViewModel
{
public int DailyServiceLogID { get; set; }
public int EmployeePositionID { get; set; }
public PositionType SelectedEmployeePosition { get; set; }
public List<PositionType> EmployeePositionList { get; set; }
public List<EmployeeSelectionListViewModel> EmployeeList { get; set; }
public EmployeeSelectionListViewModel SelectedEmployee { get; set; }
public string EmployeeName { get; set; }
public string PositionDescription { get; set; }
public DateTime? Date { get; set; }
public string WorkArea { get; set; }
public bool SelectedLog { get; set; }
}
代码隐藏
private DBContext _dbContext= new DBContext();
public ObservableCollection<DailyServiceLogsViewModel> DailyServiceLogs { get; set; }
public void OnLoad()
{
_dbContext= new DBContext();
List<EmployeeSelectionListViewModel> employeeList = _dbContext.Employees.Where(emp => emp.Active).Select(employee => new EmployeeSelectionListViewModel { EmployeeID = employee.EmployeeID, EmployeeName = employee.FirstName + " " + employee.LastName }).ToList();
DailyServiceLogs = new ObservableCollection<DailyServiceLogsViewModel>();
foreach (var serviceLog in _dbContext.DailyServiceLogs.Where(d => d.PayPeriodID == CurrentPayPeriod.PayPeriodID).OrderBy(d =>
}
ListViewTest.DataContext = this;
ListViewTest.ItemsSource = DailyServiceLogs;
}
我尝试过使用 DataTriggers,但我对它们不太熟悉
侃侃尔雅
相关分类