【发布时间】:2020-05-25 15:15:22
【问题描述】:
我正在使用 Caliburn.Micro 并尝试使用 MVVM;所以我的 ViewModel 和 Views 是分开的; 我从视图中删除了 xaml.cs 并遇到了我的 ListBox 没有绑定到公共 ObservableCollection 的问题(而且我无法弄清楚如何)
考虑以下 XAML:
<Controls:Tile Title="Track & Trace Reset"
Controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource MahApps.Brushes.ThemeForeground}"
Width="155" Height="155"
HorizontalTitleAlignment="Center"
x:Name="Button" />
<ListBox x:Name="LogEntries" ItemsSource="{Binding LogEntries}"/>
还有以下类:
public class DebugViewModel
{
public ObservableCollection<LogEntryModel> LogEntries = new ObservableCollection<LogEntryModel>(GlobalConfig.Connection.GetLogEntries());
public void Button()
{
GetLogEntries();
}
private void GetLogEntries() {
LogEntries = new ObservableCollection<LogEntryModel>(GlobalConfig.Connection.GetLogEntries());
//if filter exists, filter the list
return;
//Format based on Severity
}
}
“按钮”绑定按预期工作;但是,ListBox 不显示任何内容(我至少期望模型中应该显示一些原始文本)。 LogEntries 被填满(8 个条目) - 这也起作用;
如何解决绑定问题?
【问题讨论】:
标签: c# wpf caliburn.micro