Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表框绑定(Caliburn.Micro)-故障排除_C#_Wpf_Caliburn.micro - Fatal编程技术网

C# 列表框绑定(Caliburn.Micro)-故障排除

C# 列表框绑定(Caliburn.Micro)-故障排除,c#,wpf,caliburn.micro,C#,Wpf,Caliburn.micro,我正在使用Caliburn.Micro并尝试使用MVVM;因此,我的视图模型和视图是分开的; 我已经从视图中删除了xaml.cs,并且遇到了一个问题,即我的列表框没有绑定到公共ObservableCollection(我不知道如何绑定) 考虑以下XAML: <Controls:Tile Title="Track &amp; Trace Reset" Controls:ControlsHelper.MouseOverBorderB

我正在使用Caliburn.Micro并尝试使用MVVM;因此,我的视图模型和视图是分开的; 我已经从视图中删除了xaml.cs,并且遇到了一个问题,即我的列表框没有绑定到公共ObservableCollection(我不知道如何绑定)

考虑以下XAML:

            <Controls:Tile Title="Track &amp; 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

        }

    }
公共类DebugViewModel
{
public ObservableCollection LogEntries=新的ObservableCollection(GlobalConfig.Connection.GetLogEntries());
公共作废按钮()
{
GetLogEntries();
}
私有void GetLogEntries(){
LogEntries=新的ObservableCollection(GlobalConfig.Connection.GetLogEntries());
//如果存在筛选器,请筛选列表
返回;
//基于严重性的格式
}
}
“按钮”-装订按预期工作;然而,ListBox没有显示任何内容(至少我希望它应该显示模型中的一些原始文本)。 日志条目被填充(8个条目)-这也起作用


如何解决绑定问题?

LogEntries
应定义为绑定工作的公共属性:

public ObservableCollection<LogEntryModel> LogEntries { get; } 
   = new ObservableCollection<LogEntryModel>(GlobalConfig.Connection.GetLogEntries());

非常感谢。这确实给了我更多的工作机会;现在它只抱怨无法为LogEntryModel找到ViewModel;但这是一个简单的解决方案!
<ListBox x:Name="LogEntries" />