mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-16 22:26:36 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace UWP.CartesianChart.Events
|
||||
{
|
||||
public class MyCommand<T> : ICommand where T : class
|
||||
{
|
||||
public Predicate<T> CanExecuteDelegate { get; set; }
|
||||
public Action<T> ExecuteDelegate { get; set; }
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return CanExecuteDelegate == null || CanExecuteDelegate((T) parameter);
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
if (ExecuteDelegate != null) ExecuteDelegate((T) parameter);
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<Page x:Class="UWP.CartesianChart.Events.EventsExample"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:lvc="using:LiveCharts.Uwp"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<lvc:CartesianChart Grid.Row="1" Name="Chart" Zoom="Xy"
|
||||
DataClick="ChartOnDataClick"
|
||||
DataHover="Chart_OnDataHover"
|
||||
UpdaterTick="ChartOnUpdaterTick"
|
||||
DataClickCommand="{Binding DataClickCommand}"
|
||||
DataHoverCommand="{Binding DataHoverCommand}"
|
||||
UpdaterTickCommand="{Binding UpdaterTickCommand}">
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis RangeChanged="Axis_OnRangeChanged"
|
||||
RangeChangedCommand="{Binding RangeChangedCommand}"/>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
<lvc:CartesianChart.Series>
|
||||
<lvc:LineSeries Values="{Binding Values}"
|
||||
Fill="Transparent"
|
||||
StrokeThickness="4"
|
||||
PointGeometrySize="25"/>
|
||||
</lvc:CartesianChart.Series>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</Page>
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Diagnostics;
|
||||
using Windows.Devices.Input;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Events;
|
||||
using LiveCharts.Uwp;
|
||||
|
||||
namespace UWP.CartesianChart.Events
|
||||
{
|
||||
public partial class EventsExample : Page
|
||||
{
|
||||
public EventsExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = new ViewModel();
|
||||
}
|
||||
|
||||
public ChartValues<double> Values { get; set; } = new ChartValues<double> {4, 6, 5, 3, 5};
|
||||
|
||||
private void ChartOnDataClick(object sender, ChartPoint p)
|
||||
{
|
||||
var asPixels = Chart.ConvertToPixels(p.AsPoint());
|
||||
Debug.WriteLine("[EVENT] You clicked (" + p.X + ", " + p.Y + ") in pixels (" +
|
||||
asPixels.X + ", " + asPixels.Y + ")");
|
||||
}
|
||||
|
||||
private void Chart_OnDataHover(object sender, ChartPoint p)
|
||||
{
|
||||
Debug.WriteLine("[EVENT] you hovered over " + p.X + ", " + p.Y);
|
||||
}
|
||||
|
||||
private void ChartOnUpdaterTick(object sender)
|
||||
{
|
||||
Debug.WriteLine("[EVENT] chart was updated");
|
||||
}
|
||||
|
||||
private void Axis_OnRangeChanged(RangeChangedEventArgs eventargs)
|
||||
{
|
||||
Debug.WriteLine("[EVENT] axis range changed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Diagnostics;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Events;
|
||||
|
||||
namespace UWP.CartesianChart.Events
|
||||
{
|
||||
public class ViewModel
|
||||
{
|
||||
public ViewModel()
|
||||
{
|
||||
DataClickCommand = new MyCommand<ChartPoint>
|
||||
{
|
||||
ExecuteDelegate = p => Debug.WriteLine(
|
||||
"[COMMAND] you clicked " + p.X + ", " + p.Y)
|
||||
};
|
||||
DataHoverCommand = new MyCommand<ChartPoint>
|
||||
{
|
||||
ExecuteDelegate = p => Debug.WriteLine(
|
||||
"[COMMAND] you hovered over " + p.X + ", " + p.Y)
|
||||
};
|
||||
UpdaterTickCommand = new MyCommand<LiveCharts.Uwp.CartesianChart>
|
||||
{
|
||||
ExecuteDelegate = c => Debug.WriteLine("[COMMAND] Chart was updated!")
|
||||
};
|
||||
RangeChangedCommand = new MyCommand<RangeChangedEventArgs>
|
||||
{
|
||||
ExecuteDelegate = e => Debug.WriteLine("[COMMAND] axis range changed")
|
||||
};
|
||||
}
|
||||
|
||||
public MyCommand<ChartPoint> DataHoverCommand { get; set; }
|
||||
public MyCommand<ChartPoint> DataClickCommand { get; set; }
|
||||
public MyCommand<LiveCharts.Uwp.CartesianChart> UpdaterTickCommand { get; set; }
|
||||
public MyCommand<RangeChangedEventArgs> RangeChangedCommand { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user