using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using VistaAdmin.Infrastructure; |
using System.ComponentModel; |
using VistaAdmin.Configuration.Properties; |
using System.Windows.Media; |
using System.Windows.Media.Imaging; |
using Microsoft.Practices.EnterpriseLibrary.Logging; |
using VistaAdmin.Composite.Extensions; |
using System.Windows.Input; |
using System.IO; |
using System.Windows; |
using System.Reflection; |
using System.Collections.ObjectModel; |
using Telerik.Windows.Controls; |
using System.Windows.Data; |
using VistaAdmin.Help.Interface; |
namespace VistaAdmin.Configuration.Applications |
{ |
internal class ConfigurationPresentationModel : PresentationModel<IConfigView>, IHeaderInfoProvider |
{ |
private static readonly PropertyInfo HeaderInfoProperty = TypeManager.GetProperty<ConfigurationPresentationModel>(x => x.HeaderInfo); |
private readonly IMessageService messageService; |
private IDynamicHelp dynamicHelp; |
private readonly IApplicationContainer container; |
private RadWindow window; |
private readonly DelegateCommand openWindowCommand; |
private readonly IConfigView view; |
public ConfigurationPresentationModel(IApplicationContainer container, IConfigView view, IMessageService messageService) |
: base(view) |
{ |
this.container = container; |
this.messageService = messageService; |
this.view = view; |
dynamicHelp = container.TryResolve<IDynamicHelp>(); |
openWindowCommand = new DelegateCommand(Open, CanOpenExecute); |
this.window = this.CreateWindow(); |
} |
public string HeaderInfo |
{ |
get { return Resources.Title; } |
} |
public ImageSource HeaderIcon |
{ |
get { return new BitmapImage(ResourceService.GetPackUri("Resources/Config.ico")); } |
} |
private static void Log(string message, System.Diagnostics.TraceEventType severity) |
{ |
LogEntry entry = new LogEntry(); |
entry.Severity = severity; |
entry.Message = message; |
entry.Title = "VistaAdminConfiguration"; |
entry.Categories.Add("Configuration"); |
Logger.Write(entry); |
} |
public ICommand OpenWindowCommand { get { return openWindowCommand; } } |
private bool CanOpenExecute() |
{ |
return !this.window.IsOpen; |
} |
public void Open() |
{ |
if (!this.window.IsOpen) |
{ |
this.window.ShowDialog(); |
} |
} |
private RadWindow CreateWindow() |
{ |
window = new RadWindow(); |
window.DataContext = this.view.DataContext; |
window.Closed += new EventHandler<WindowClosedEventArgs>(window_Closed); |
window.Opened += new RoutedEventHandler(window_Opened); |
return window; |
} |
void window_Opened(object sender, RoutedEventArgs e) |
{ |
//this.window.IsOpen = true; |
} |
void window_Closed(object sender, WindowClosedEventArgs e) |
{ |
//this.IsOpen = false; |
} |
} |
} |
<telerikNavigation:RadWindow x:Class="VistaAdmin.Configuration.Presentation.ConfigurationView" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:v="clr-namespace:VistaAdmin.Configuration.Presentation" |
xmlns:p="clr-namespace:VistaAdmin.Configuration.Properties" |
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerikRibbonBar="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonBar" |
xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:xamlHelpers="clr-namespace:VistaAdmin.Configuration.Domain" |
Header="{Binding HeaderInfo}" |
mc:Ignorable="d" Height="450" Width="450"> |
<StackPanel> |
<ToolBar> |
<Button x:Name="configSaveButton" ToolTip="{x:Static p:Resources.Save}" Command="{Binding SaveConfigCommand}"> |
<Image Source="../Resources/save.png" Width="16" Height="16"/> |
</Button> |
<Button x:Name="configValidateButton" ToolTip="{x:Static p:Resources.Validate}" Command="{Binding DBValidateCommand}"> |
<Image Source="../Resources/db.png" Width="16" Height="16"/> |
</Button> |
</ToolBar> |
<Grid> |
</Grid> |
</StackPanel> |
</telerikNavigation:RadWindow> |
I tried to save chart as image as shown in below code,got error "The parameter value must be greater than zero.Parameter name: pixelWidth". Here my requrement is , Generating chart programatically and saving the same to JPEG in specified folder path. Anyone help me in doing this?
SeriesMapping sm1 = new SeriesMapping();
sm1.SeriesDefinition = new LineSeriesDefinition();
sm1.LegendLabel = "Line Series 1";
sm1.CollectionIndex = 0;
ItemMapping im1 = new ItemMapping();
im1.DataPointMember = DataPointMember.YValue;
sm1.ItemMappings.Add(im1);
SeriesMapping sm2 = new SeriesMapping();
sm2.SeriesDefinition = new LineSeriesDefinition();
sm2.LegendLabel = "Line Series 2";
sm2.CollectionIndex = 1;
ItemMapping im2 = new ItemMapping();
im2.DataPointMember = DataPointMember.YValue;
sm2.ItemMappings.Add(im2);
var itemsSource = new List<double>[] { new List<double> { 22, 12, 66, 76 }, new List<double> { 76, 45, 53, 43 } };
this.RadChart1.SeriesMappings.Add(sm1);
this.RadChart1.SeriesMappings.Add(sm2);
this.RadChart1.ItemsSource = itemsSource;
RadChart1.ExportToImage(
@"d:\remove\abc.png");
grid.Children.Add(RadChart1);
I tried to change ExportToImage method as follows, but there is no class named 'PngBitmapEncoder' under "Telerik.Windows.Media.Imaging" namespace in WPF related DLLs provided by Telerik, but this is working fine in Silverlight related DLLs provided by Telerik. Can anyone help me here to save chat as image in JPEG format.
Stream fileStream = File.Create(@"d:\ss\ss.png") ;
RadChart1.ExportToImage(fileStream, new Telerik.Windows.Media.Imaging.PngBitmapEncoder());
fileStream.Close();
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 Telerik.Windows.Controls;
using Telerik.Windows.Data;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<Person> allPersons = new List<Person>();
createGridColumns();
allPersons.Add(new Person() { LastName = "Doe", FirstName = "John", Number1 = 1, Number2 = 2, Number3 = 3 });
allPersons.Add(new Person() { LastName = "Fraser", FirstName = "Joe", Number1 = 4, Number2 = 2, Number3 = 6 });
allPersons.Add(new Person() { LastName = "Alban", FirstName = "Ricardo", Number1 = 7, Number2 = 8, Number3 = 9 });
gridViewTest.ItemsSource = allPersons;
}
private void createGridColumns()
{
GridViewDataColumn col1 = new GridViewDataColumn();
GridViewDataColumn col2 = new GridViewDataColumn();
GridViewDataColumn col3 = new GridViewDataColumn();
GridViewDataColumn col4 = new GridViewDataColumn();
GridViewDataColumn col5 = new GridViewDataColumn();
col1.Header = "LastName";
col1.UniqueName = "col1";
col1.DataMemberBinding = new Binding("LastName");
col1.AggregateFunctions.Add(new CountFunction() { Caption = "Count: " });
col2.Header = "FirstName";
col2.UniqueName = "col2";
col2.DataMemberBinding = new Binding("FirstName");
col2.AggregateFunctions.Add(new FirstFunction() { Caption = "First: " });
col2.AggregateFunctions.Add(new LastFunction() { Caption = "Last: " });
col2.AggregateFunctions.Add(new MinFunction() { Caption = "Min: " });
col2.AggregateFunctions.Add(new MaxFunction() { Caption = "Max: " });
col3.Header = "Number1";
col3.UniqueName = "col3";
col3.DataFormatString = "C2";
col3.DataMemberBinding = new Binding("Number1");
col3.AggregateFunctions.Add(new MinFunction() { Caption = "Min: " });
col3.AggregateFunctions.Add(new MaxFunction() { Caption = "Max: " });
col4.Header = "Number2";
col4.UniqueName = "col4";
col4.DataFormatString = "C2";
col4.DataMemberBinding = new Binding("Number2");
col4.AggregateFunctions.Add(new AverageFunction() { Caption = "Avg: ", SourceFieldType=typeof(decimal) }); // *** Put this line in comment to have a working app ***
col5.Header = "Number3";
col5.UniqueName = "col5";
col5.DataFormatString = "C2";
col5.DataMemberBinding = new Binding("Number3");
col5.AggregateFunctions.Add(new SumFunction() { Caption = "Sum: ", SourceFieldType = typeof(decimal) }); // *** Put this line in comment to have a working app ***
gridViewTest.Columns.Add(col1);
gridViewTest.Columns.Add(col2);
gridViewTest.Columns.Add(col3);
gridViewTest.Columns.Add(col4);
gridViewTest.Columns.Add(col5);
}
}
public class Person
{
public object LastName { get; set; }
public object FirstName { get; set; }
public object Number1 { get; set; }
public object Number2 { get; set; }
public object Number3 { get; set; }
}
}
<
Window.Resources
>
<
CollectionViewSource
x:Key
=
"orderViewSource"
/>
</
Window.Resources
>
<
Grid
>
<
ItemsControl
x:Name
=
"rptOrders"
ItemsSource
=
"{Binding Source={StaticResource orderViewSource}}"
>
<
ItemsControl.ItemTemplate
>
<
DataTemplate
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"160px"
/>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Label
Content
=
"{Binding Path=Name}"
Grid.Column
=
"0"
VerticalAlignment
=
"Center"
></
Label
>
<
telerik:RadComboBox
x:Name
=
"rcbOrder"
Grid.Column
=
"1"
SelectedItem
=
"{Binding Path=Order}"
>
<
telerik:RadComboBoxItem
Content
=
"Extra Hot"
/>
<
telerik:RadComboBoxItem
Content
=
"Hot"
/>
<
telerik:RadComboBoxItem
Content
=
"Mild"
/>
</
telerik:RadComboBox
>
</
Grid
>
</
DataTemplate
>
</
ItemsControl.ItemTemplate
>
</
ItemsControl
>
</
Grid
>
((CollectionViewSource)(FindResource(
"orderViewSource"
))).Source = Data.StaffOrders;
public
class
Data
{
public
static
ObservableCollection<StaffMember> StaffOrders {
get
{
return
//loaddata; } }
public
class
StaffMember
{
public
Int32 StaffID {
get
;
set
; }
public
String Name {
get
;
set
; }
public
String Email {
get
;
set
; }
public
String Order {
get
;
set
; }
}
}