TeeChart ScrollPager tool doesn’t work in WPF project - c#

I want to use TeeChart (http://www.teechart.net/) ScrollPager tool in my WPF project, but it doesn’t work. (TeeChart.WPF.dll version 4.1.2012.2287)
http://img190.imageshack.us/img190/4900/scrwpf.png
namespace TeeChart
{
using Steema.TeeChart.WPF.Themes;
using Steema.TeeChart.WPF.Tools;
using Steema.TeeChart.WPF.Styles;
using Steema.TeeChart.WPF.Drawing;
public partial class MainWindow
{
private Line _series;
private ScrollPager _tool;
BlackIsBackTheme _black;
public MainWindow()
{
InitializeComponent();
_series = new Line();
tChart1.Series.Add(_series);
tChart1.Chart.Aspect.View3D = false;
tChart1.Header.Visible = false;
tChart1.Legend.Visible = false;
_series.FillSampleValues(500);
_black = new BlackIsBackTheme(tChart1.Chart);
_black.Apply();
_tool = new ScrollPager();
tChart1.Tools.Add(_tool);
_tool.Series = _series;
_black = new BlackIsBackTheme(_tool.SubChartTChart.Chart);
_black.Apply();
_tool.SubChartTChart.Panel.Pen.Visible = false;
_tool.SubChartTChart.Panel.Bevel.Inner = BevelStyles.None;
_tool.SubChartTChart.Panel.Bevel.Outer = BevelStyles.None;
}
}
}
In WinForms project it works fine.
http://img692.imageshack.us/img692/4527/scrwinforms.png
namespace TeeChartWinForms
{
using System.Windows.Forms;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Themes;
using Steema.TeeChart.Tools;
public partial class Form1 : Form
{
private Line _series;
private ScrollPager _tool;
BlackIsBackTheme _black;
public Form1()
{
InitializeComponent();
_series = new Line();
tChart1.Series.Add(_series);
tChart1.Chart.Aspect.View3D = false;
tChart1.Header.Visible = false;
tChart1.Legend.Visible = false;
_series.FillSampleValues(500);
_black = new BlackIsBackTheme(tChart1.Chart);
_black.Apply();
_tool = new ScrollPager();
tChart1.Tools.Add(_tool);
_tool.Series = _series;
_black = new BlackIsBackTheme(_tool.SubChartTChart.Chart);
_black.Apply();
_tool.SubChartTChart.Panel.Pen.Visible = false;
_tool.SubChartTChart.Panel.Bevel.Inner = BevelStyles.None;
_tool.SubChartTChart.Panel.Bevel.Outer = BevelStyles.None;
}
}
}
Thanks,
Alex

Seems that your problem doesn't appear using next code:
Code c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 Steema.TeeChart.WPF;
using Steema.TeeChart.WPF.Styles;
using System.IO;
using System.Windows.Markup;
using Steema.TeeChart.WPF.Tools;
using Steema.TeeChart.WPF.Drawing;
using Steema.TeeChart.WPF.Themes;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
private Steema.TeeChart.WPF.Styles.Line series;
private ScrollPager tool;
BlackIsBackTheme black;
public MainWindow()
{
InitializeComponent();
series = new Steema.TeeChart.WPF.Styles.Line();
tChart1.Series.Add(series);
tChart1.Chart.Aspect.View3D = false;
tChart1.Header.Visible = false;
tChart1.Legend.Visible = false;
series.FillSampleValues(500);
black = new BlackIsBackTheme(tChart1.Chart);
black.Apply();
tool = new ScrollPager(tChart1.Chart);
tool.Series = series;
black = new BlackIsBackTheme(tool.SubChartTChart.Chart);
black.Apply();
tool.SubChartTChart.Panel.Pen.Visible = false;
tool.SubChartTChart.Panel.Bevel.Inner = BevelStyles.None;
tool.SubChartTChart.Panel.Bevel.Outer = BevelStyles.None;
}
}
}
code xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tc="clr-namespace:Steema.TeeChart.WPF;assembly=TeeChart.WPF"
Title="MainWindow" SizeToContent="WidthAndHeight" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="516" d:DesignWidth="492">
<Grid >
<AdornerDecorator Margin="25,12,27,65">
<tc:TChart Name="tChart1" Height="226" Width="412" />
</AdornerDecorator>
</Grid>
</Window>
And I get the same results as winforms. Please try again if using my code your problem are solved or it still appears. If your problem doesn't solve could you please send a simple example project we can run "as-is" to reproduce the problem here at steema.net/upload?
Thanks,
Best regards
Sandra

Related

Wait a animation to end before another starts WPF [duplicate]

I'm learning wpf and at the same time developing an app with it. I'm having a hard time figuring out how i can run something when a doubleanimation (Or other sorts) is done. For instance:
DoubleAnimation myanim = new DoubleAnimation();
myanim.From = 10;
myanim.To = 100;
myanim.Duration = new Duration(TimeSpan.FromSeconds(3));
myview.BeginAnimation(Button.OpacityPropert, myanim);
//Code to do something when animation ends
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Windows.Media.Animation;
namespace app
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation widthbutton = new DoubleAnimation();
widthbutton.From = 55;
widthbutton.To = 100;
widthbutton.Duration = new Duration(TimeSpan.FromSeconds(1.5));
button1.BeginAnimation(Button.HeightProperty, widthbutton);
DoubleAnimation widthbutton1 = new DoubleAnimation();
widthbutton1.From = 155;
widthbutton1.To = 200;
widthbutton1.Duration = new Duration(TimeSpan.FromSeconds(1.5));
button1.BeginAnimation(Button.WidthProperty, widthbutton1);
widthbutton.Completed += new EventHandler(myanim_Completed);
}
private void myanim_Completed(object sender, EventArgs e)
{
//your completed action here
MessageBox.Show("Animation done!");
}
}
}
How is this accomplishable? I have read quite a few other posts about this, but they all explain it using xaml, however i would like to do it using c# code. Thanks!
You can attach an event handler to the DoubleAnimation's Completed event.
myanim.Completed += new EventHandler(myanim_Completed);
private void myanim_Completed(object sender, EventArgs e)
{
//your completed action here
}
Or, if you prefer it inline, you can do
myanim.Completed += (s,e) =>
{
//your completed action here
};
Remember to attach the handler before starting the animation otherwise it won't fire.

'The calling thread cannot access this object because a different thread owns it' error using LiveCharts plotting library in C# winforms

My Form contains a button and a chart added as shown below.
My code is built such that a separate thread continuously gets data from the sender (which is being sent using the UDP protocol of communication), processes it and adds it to the global GLineSeries object 'gls'. GLineSeries is basically a class of the library which is basically just a list of the datapoints of the graph. My aim is that when the button is clicked this series is added to the chart in the form (cartesianChart1) and the plot shows. This is done using the line cartesianChart1.Series.Add(gls); The code for this is shown below (Form1.cs file)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.WinForms;
using LiveCharts.Wpf;
using LiveCharts.Defaults;
using LiveCharts.Geared;
using System.Windows.Shell;
namespace livecharts_example
{
public partial class Form1 : Form
{
LiveCharts.WinForms.CartesianChart cartesianChart1 = new LiveCharts.WinForms.CartesianChart();
GLineSeries gls;
Thread t;
public Form1()
{
InitializeComponent();
cartesianChart1.Dock = DockStyle.Fill;
this.Controls.Add(cartesianChart1);
t = new Thread(() => {
UdpClient dataUdpClient = new UdpClient(90);
string carIP = "127.0.0.1";
IPEndPoint carIpEndPoint = new IPEndPoint(IPAddress.Parse(carIP), 0);
Byte[] receiveBytes;
gls = new GLineSeries();
gls.Values = new GearedValues<ObservablePoint>();
while (true)
{
receiveBytes = dataUdpClient.Receive(ref carIpEndPoint);
ObservablePoint op = new ObservablePoint(BitConverter.ToInt32(receiveBytes, 0), BitConverter.ToSingle(receiveBytes, 8));
gls.Values.Add(op);
}
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void button1_Click(object sender, EventArgs e)
{
cartesianChart1.Series.Add(gls);
}
}
}
The problem is that when the button is pressed the program jumps to the program.cs file and throws the error as shown below. I also tried aborting the thread 't' and then adding the lineseries to the chart but the error still arises. Can someone please help?
The following code worked. Thanks for all the suggestions
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.WinForms;
using LiveCharts.Wpf;
using LiveCharts.Defaults;
using LiveCharts.Geared;
using System.Windows.Shell;
using System.Windows;
using System.Collections.ObjectModel;
namespace livecharts_example
{
public partial class Form1 : Form
{
LiveCharts.WinForms.CartesianChart cartesianChart1 = new LiveCharts.WinForms.CartesianChart();
Thread t;
static GLineSeries gls;
public Form1()
{
InitializeComponent();
cartesianChart1.Dock = DockStyle.Fill;
this.Controls.Add(cartesianChart1);
t = new Thread(() => {
UdpClient dataUdpClient = new UdpClient(90);
string carIP = "127.0.0.1";
IPEndPoint carIpEndPoint = new IPEndPoint(IPAddress.Parse(carIP), 0);
Byte[] receiveBytes;
cartesianChart1.Invoke(new Action(() =>
{
Form1.gls = new GLineSeries(); Form1.gls.Values = new GearedValues<ObservablePoint>();
}));
while (true)
{
receiveBytes = dataUdpClient.Receive(ref carIpEndPoint);
ObservablePoint op = new ObservablePoint(BitConverter.ToInt32(receiveBytes, 0), BitConverter.ToSingle(receiveBytes, 8));
cartesianChart1.Invoke(new Action(() => {
gls.Values.Add(op);
}));
}
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
private void button1_Click(object sender, EventArgs e)
{
cartesianChart1.Invoke(new Action(()=> {
cartesianChart1.Series.Add(gls);
}));
}
}
}

C# WPF read console output

I'm writing an app that displays your current hashrate in Ethereum (A cryptocurrency like Bitcoin), and I need to somehow get the continuous output from the Command line that is running. This is what I have so far, but it is not printing to the program output:
pProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
// Prepend line numbers to each line of the output.
if (!String.IsNullOrEmpty(e.Data))
{
System.Console.Write(e.Data);
}
});
//Wait for process to finish
pProcess.WaitForExit();
What is not working with this code? I'm guessing there's something messed up with the event handler, but I don't know what.
Copy and paste it to your code I modified it for you:
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 System.Diagnostics;
namespace ETHMinerVisualiser
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void MineButton_Click(object sender, RoutedEventArgs e)
{
Task.Run(() => { startMining(); });
}
public void startMining()
{
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = #"E:/Documents/ETH/ETHMinerVisualiser/ethminer-cuda-0.9.41-new/ethminer.exe";
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = "-F eu1.ethermine.org:5555/0x9c3f6281b123541f10c9bf37a8f273aa2a774d17.PCGPU -C";
pProcess.StartInfo.UseShellExecute = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Optional
pProcess.StartInfo.WorkingDirectory = "";
//Start the process
pProcess.Start();
//pProcess.StartInfo.CreateNoWindow = true;
//pProcess.BeginOutputReadLine();
pProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
// Prepend line numbers to each line of the output.
if (!String.IsNullOrEmpty(e.Data))
{
//System.Console.Write(e.Data);
Debug.WriteLine(e.Data);
}
});
//Wait for process to finish
pProcess.BeginOutputReadLine();
pProcess.WaitForExit();
}
}
}

Beginner Kinect Programming - "'args' does not exsist in the current context"?

Ok so I started writing an app following the how-to-kinect series from Microsoft and everything was going well until I wrote this:
using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
{
}
For some reason it keeps saying args does not exist in the current context and I have no idea why..here is my full code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using WindowsPreview.Kinect;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace KinectApp1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
/*Getting the Kinect Sensor*/
KinectSensor Sensor;
/*Getting the Infared Reader*/
InfraredFrameReader IRReader;
/*This is IR Data Form*/
ushort[] IRData;
/*Converting the Data (Buffer) */
byte[] IRDataConverted;
/*Writing the Bitmap Image Described in XAML*/
WriteableBitmap IRBitmap;
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
/*Get the sensor in the loaded frame*/
Sensor = KinectSensor.GetDefault();
/*Get the reader from the Source on the Sensor*/
IRReader = Sensor.InfraredFrameSource.OpenReader();
/*Frame Description for the Infrared and see how big they are*/
FrameDescription FD = Sensor.InfraredFrameSource.FrameDescription;
IRData = new ushort[FD.LengthInPixels];
IRDataConverted = new byte[FD.LengthInPixels * 4];
IRBitmap = new WriteableBitmap(FD.Width, FD.Height);
Image.Source = IRBitmap;
/*Start Sensor*/
Sensor.Open();
/*Subscribe to the event off the Reader*/
IRReader.FrameArrived += IRReader_FrameArrived;
}
void IRReader_FrameArrived(InfraredFrameReader sender, InfraredFrameArrivedEventArgs e)
{
using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
{
if (IRFrame != null)
{
IRFrame.CopyFrameDataToArray(IRData);
for (int i = 0; i < IRData.Length; i++)
{
byte intensity = (byte)(IRData[i]>>8);
IRDataConverted[i*4] = intensity;
IRDataConverted[i*4 + 1] = intensity;
IRDataConverted[i*4 + 2] = intensity;
IRDataConverted[i*4 + 3] = 255;
}
IRDataConverted.CopyTo(IRBitmap.PixelBuffer);
IRBitmap.Invalidate();
}
}
}
}
}
Can anyone kindly explain why this has happened? I am pretty confused,
Thanks in Advance.
P.S this is the video I was following:
http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx
Well it's been answered so I'm not sure what else to do apart from answer it:
As Preston Guillot said in the comments:
"There is no variable named args in scope in the IRReader_FrameArrived method. You have a parameter of type InfraredFrameArrivedEventArgs named e that I'm guessing you meant to use"

Compile error on Animation in Windows Phone

I am new with Windows Phone animation and using the below code but it give me compile error:
'System.Windows.Controls.Button' does not contain a definition for 'BeginAnimation' and no extension method 'BeginAnimation' accepting a first argument of type 'System.Windows.Controls.Button' could be found (are you missing a using directive or an assembly reference?)
Which reference I am missing?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
private void button1_Click(object sender, RoutedEventArgs e)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 30;
da.To = 100;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
button1.BeginAnimation(Button.HeightProperty, da);
}
The UIElement.BeginAnimation method does not exist in WP7. Instead, you will need to create a storyboard as follows:
private void button1_Click(object sender, RoutedEventArgs e)
{
var sb = new Storyboard();
var db = CreateDoubleAnimation(30, 100,
button1, Button.HeightProperty, TimeSpan.FromMilliseconds(1000));
sb.Children.Add(db);
sb.Begin();
}
private static DoubleAnimation CreateDoubleAnimation(double from, double to,
DependencyObject target, object propertyPath, TimeSpan duration)
{
var db = new DoubleAnimation();
db.To = to;
db.From = from;
db.Duration = duration;
Storyboard.SetTarget(db, target);
Storyboard.SetTargetProperty(db, new PropertyPath(propertyPath));
return db;
}

Categories

Resources