UWP Toolkit DataGrid-如何将ItemSource正确绑定到模型?

时间:2019-05-20 04:58:41

标签: c# uwp datagrid

我正在使用UWP Toolkit的DataGrid来显示来自从SQLite数据库提取的模型中的记录。我在将DataGrid绑定到模型方面遇到了挑战,到目前为止已经创建了以下内容:

onUpdate

我想将DataGrid ItemSource绑定到可定义的ActivityLogEntries集合,定义为:

<controls:DataGrid x:Name="ActivityLogDataGrid" AutoGenerateColumns="False" ItemsSource="{Binding ActivityLogEntries}" 
                           GridLinesVisibility="All"
                           HeadersVisibility="Column"
                           AlternatingRowBackground="LightGray"
                           SelectedItem="Yellow"
                           VerticalScrollBarVisibility="Visible"
                           >
            <controls:DataGrid.Columns>
                <controls:DataGridTextColumn  Header="Entry Date" Binding="{Binding EntryDate}"/>
                <controls:DataGridTextColumn Header="Message" Binding="{Binding Message}"/>
            </controls:DataGrid.Columns>

我还创建了一个接口IActivityLogService,如下所示:

public ObservableCollection<ActivityLogEntryModel> ActivityLogEntries { get; private set; }
 private  MainViewModel()
    {

        timer = new DispatcherTimer
        {
            Interval = TimeSpan.FromMilliseconds(500)
        };
        timer.Start();
        timer.Tick += TimeOnTick;

        PlayCommand = new DelegateCommand(Play);
        StopCommand = new DelegateCommand(Stop);
        RecordCommand = new DelegateCommand(Record);
        PauseCommand = new DelegateCommand(Pause);
        OutputDevices = new ObservableCollection<DeviceInformation>();
        RecordingDevices = new ObservableCollection<DeviceInformation>();
        ActivityLogEntries = new ObservableCollection<ActivityLogEntryModel>();

        Volume = 100;
        PlaybackSpeed = 100;
        recordingFormat = MediaEncodingProfile.CreateWav(AudioEncodingQuality.High);
        recordingFormat.Audio = AudioEncodingProperties.CreatePcm(16000,1,16);  
        EnableCommands(false);
        player = new MediaPlayerElement();
    }

如何正确地将DataGrid的ItemSource绑定到我的GetActivityLogEntriesAsync方法?

0 个答案:

没有答案