using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Data;
|
using System.Windows.Documents;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using System.Windows.Media.Imaging;
|
using System.Windows.Navigation;
|
using System.Windows.Shapes;
|
|
namespace Bro.UI.Ctrls
|
{
|
/// <summary>
|
/// LogCtrl.xaml 的交互逻辑
|
/// </summary>
|
public partial class LogCtrl : UserControl
|
{
|
public LogCtrl()
|
{
|
InitializeComponent();
|
}
|
|
public static readonly DependencyProperty LogListProperty;
|
|
public ObservableCollection<string> LogList
|
{
|
get => GetValue(LogListProperty) as ObservableCollection<string>;
|
set => SetValue(LogListProperty, value);
|
}
|
|
static LogCtrl()
|
{
|
LogListProperty = DependencyProperty.Register("LogList", typeof(ObservableCollection<string>), typeof(LogCtrl), new PropertyMetadata(new ObservableCollection<string>(), OnLogListPropertyChanged));
|
}
|
|
private static void OnLogListPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
{
|
LogCtrl ctrl = d as LogCtrl;
|
if (ctrl != null)
|
{
|
ctrl.LogList = e.NewValue as ObservableCollection<string>;
|
ctrl.lvLog.ItemsSource = ctrl.LogList;
|
|
ctrl.LogList.CollectionChanged += ctrl.LogList_CollectionChanged;
|
}
|
}
|
|
private void LogList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
{
|
lvLog.ItemsSource = LogList;
|
|
if (!lvLog.IsFocused && lvLog.Items.Count > 0)
|
{
|
lvLog.ScrollIntoView(lvLog.Items[lvLog.Items.Count - 1]);
|
}
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
LogList.Clear();
|
}
|
}
|
}
|