【发布时间】:2021-01-18 16:29:10
【问题描述】:
所以在我的应用程序中,我打开了特定进程,读取它的输出并将其放入我的ListView:
<ListView Name="listViewResults"
ItemsSource="{Binding Results}"/>
视图模型
private ObservableCollection<string> results;
过程输出
private void OutputHandler(object sender, DataReceivedEventArgs e)
{
if (line != null)
{
results.Add(line);
}
}
所以我创建了另一个property:
private string currentLog;
public string CurrentLog
{
get { return currentLog; }
set
{
currentLog = value;
NotifyPropertyChanged("CurrentLog");
}
}
并将其添加到我的 OutputHandler method:
CurrentLog = line;
并在我的ListView SelectedItem property 在我的XAML 中使用它:
<ListView Name="listViewResults"
ItemsSource="{Binding Results}"
SelectedItem="{Binding CurrentLog}"/>
结果还是需要手动向下滚动。
【问题讨论】:
-
我正在使用 WPF,有没有机会使用 XAML 而不是后面的代码来做到这一点?