如何将记录插入UWP Community Toolkit DataGrid?

时间:2019-05-17 18:14:07

标签: c# uwp datagrid

我正在使用UWP Community Toolkit的DataGrid来显示来自ActivityLogEntryModel的信息,如下所示:

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

        </controls:DataGrid>
        <Button Command="{Binding CreateActivityLogEntryAsync}">
            <TextBlock Text="Add Entry"></TextBlock>
        </Button>

ViewModel可观察的集合:

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下方添加了一个Button控件,单击该控件时将显示一个带有ActivityLogEntryModel类的空字段的对话框。如何创建此对话框并确保将更改保存到模型中,并确保使用新条目刷新DataGrid?

0 个答案:

没有答案