mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-17 06:36:36 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Wpf.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
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<UserControl x:Class="Wpf.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="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock>
|
||||
<TextBlock >Mouse at: </TextBlock>
|
||||
<TextBlock Name="X"></TextBlock>
|
||||
<TextBlock >, </TextBlock>
|
||||
<TextBlock Name="Y"></TextBlock>
|
||||
</TextBlock>
|
||||
<lvc:CartesianChart Grid.Row="1" Name="Chart" Zoom="Xy"
|
||||
MouseMove="ChartMouseMove"
|
||||
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="4,6,5,3,5" Fill="Transparent" StrokeThickness="4"
|
||||
Panel.ZIndex="2" PointGeometrySize="25"/>
|
||||
</lvc:CartesianChart.Series>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Events;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.Events
|
||||
{
|
||||
public partial class EventsExample : UserControl
|
||||
{
|
||||
public EventsExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = new ViewModel();
|
||||
}
|
||||
|
||||
private void ChartOnDataClick(object sender, ChartPoint p)
|
||||
{
|
||||
var asPixels = Chart.ConvertToPixels(p.AsPoint());
|
||||
Console.WriteLine("[EVENT] You clicked (" + p.X + ", " + p.Y + ") in pixels (" +
|
||||
asPixels.X + ", " + asPixels.Y + ")");
|
||||
}
|
||||
|
||||
private void Chart_OnDataHover(object sender, ChartPoint p)
|
||||
{
|
||||
Console.WriteLine("[EVENT] you hovered over " + p.X + ", " + p.Y);
|
||||
}
|
||||
|
||||
private void ChartOnUpdaterTick(object sender)
|
||||
{
|
||||
Console.WriteLine("[EVENT] chart was updated");
|
||||
}
|
||||
|
||||
private void Axis_OnRangeChanged(RangeChangedEventArgs eventargs)
|
||||
{
|
||||
Console.WriteLine("[EVENT] axis range changed");
|
||||
}
|
||||
|
||||
private void ChartMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var point = Chart.ConvertToChartValues(e.GetPosition(Chart));
|
||||
|
||||
X.Text = point.X.ToString("N");
|
||||
Y.Text = point.Y.ToString("N");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Events;
|
||||
|
||||
namespace Wpf.CartesianChart.Events
|
||||
{
|
||||
public class ViewModel
|
||||
{
|
||||
public ViewModel()
|
||||
{
|
||||
DataClickCommand = new MyCommand<ChartPoint>
|
||||
{
|
||||
ExecuteDelegate = p => Console.WriteLine(
|
||||
"[COMMAND] you clicked " + p.X + ", " + p.Y)
|
||||
};
|
||||
DataHoverCommand = new MyCommand<ChartPoint>
|
||||
{
|
||||
ExecuteDelegate = p => Console.WriteLine(
|
||||
"[COMMAND] you hovered over " + p.X + ", " + p.Y)
|
||||
};
|
||||
UpdaterTickCommand = new MyCommand<LiveCharts.Wpf.CartesianChart>
|
||||
{
|
||||
ExecuteDelegate = c => Console.WriteLine("[COMMAND] Chart was updated!")
|
||||
};
|
||||
RangeChangedCommand = new MyCommand<RangeChangedEventArgs>
|
||||
{
|
||||
ExecuteDelegate = e => Console.WriteLine("[COMMAND] Axis range changed")
|
||||
};
|
||||
}
|
||||
|
||||
public MyCommand<ChartPoint> DataHoverCommand { get; set; }
|
||||
public MyCommand<ChartPoint> DataClickCommand { get; set; }
|
||||
public MyCommand<LiveCharts.Wpf.CartesianChart> UpdaterTickCommand { get; set; }
|
||||
public MyCommand<RangeChangedEventArgs> RangeChangedCommand { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user