using Bro.Common.Model;
using System;
using System.Collections.Generic;
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;
using T047.Process;
namespace Bro.UI.RunRelated
{
///
/// CoordinateDisplayCtrl.xaml 的交互逻辑
///
public partial class CoordinateDisplayCtrl : UserControl
{
public CoordinateDisplayCtrl()
{
InitializeComponent();
lvResults.ItemsSource = PointsSource;
//lvResults.PreviewMouseWheel += (sender, e) =>
// {
// var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
// eventArg.RoutedEvent = UIElement.MouseWheelEvent;
// eventArg.Source = sender;
// lvResults.RaiseEvent(eventArg);
// };
}
public static readonly DependencyProperty PointsSourceProperty;
public IEnumerable PointsSource
{
get => GetValue(PointsSourceProperty) as IEnumerable;
set => SetValue(PointsSourceProperty, value);
}
static CoordinateDisplayCtrl()
{
List list = new List() { };
//for (int i = 0; i < 10; i++)
//{
// ComplexPoint point = new ComplexPoint() { ImagePoint = new DirectionAidPoint(i * 0.123f, i), PlatPoint = new DirectionAidPoint(i, i) };
// if (i < 6)
// {
// point.IsCurrent = false;
// }
// else if (i == 6)
// {
// point.IsCurrent = true;
// }
// list.Add(point);
//}
PointsSourceProperty = DependencyProperty.Register("PointsSource", typeof(IEnumerable), typeof(CoordinateDisplayCtrl), new PropertyMetadata(list, OnPointsSourcePropertyChanged));
}
private static void OnPointsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
CoordinateDisplayCtrl ctrl = d as CoordinateDisplayCtrl;
if (ctrl != null)
{
var points = e.NewValue as IEnumerable;
ctrl.lvResults.ItemsSource = points;
ctrl.ShowCurrentPoint();
//foreach (ComplexPoint p in points)
//{
// p.PropertyChanged -= ctrl.P_PropertyChanged;
// p.PropertyChanged += ctrl.P_PropertyChanged;
//}
}
}
private void P_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if ((e.PropertyName == "IsCurrent") && (((ComplexPoint)sender).IsCurrent ?? false))
{
ShowCurrentPoint();
}
}
private void ShowCurrentPoint()
{
//int totalNum = lvResults.Items.Count;
//if (totalNum <= 0)
// return;
//int rowDisplayNum = (int)(lvResults.ActualHeight / 25.0 / 2.0);
//ComplexPoint point = lvResults.Items[totalNum - 1] as ComplexPoint;
//for (int i = totalNum - 1; i >= 0; i--)
//{
// if (((ComplexPoint)lvResults.Items[i]).IsCurrent ?? false)
// {
// do
// {
// if ((i + rowDisplayNum) < totalNum)
// {
// point = (ComplexPoint)lvResults.Items[i + rowDisplayNum];
// }
// rowDisplayNum--;
// } while (rowDisplayNum >= 0 && point == null);
// break;
// }
//}
//lvResults.Dispatcher.Invoke(() => lvResults.ScrollIntoView(point));
if (lvResults.Items.Count <= 0)
return;
lvResults.Dispatcher.Invoke(() => lvResults.ScrollIntoView(lvResults.Items[lvResults.Items.Count - 1]));
}
private void lvResults_SizeChanged(object sender, SizeChangedEventArgs e)
{
ShowCurrentPoint();
}
}
}