Skip to content

Commit 2c73c10

Browse files
Merge pull request #3 from Priyadharshini-Sf4862/WPF-956968-KBImprovement
WPF-956968-Updated the WPF KB sample and readme file
2 parents b075625 + 52613da commit 2c73c10

19 files changed

+133
-510
lines changed

WPF_Sample/Sample/App.xaml renamed to CustomLegendSample/App.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<Application x:Class="Sample.App"
1+
<Application x:Class="CustomLegendSample.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:CustomLegendSample"
45
StartupUri="MainWindow.xaml">
56
<Application.Resources>
67

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Configuration;
1+
using System.Configuration;
42
using System.Data;
5-
using System.Linq;
6-
using System.Threading.Tasks;
73
using System.Windows;
84

9-
namespace Sample
5+
namespace CustomLegendSample
106
{
117
/// <summary>
128
/// Interaction logic for App.xaml
139
/// </summary>
1410
public partial class App : Application
1511
{
1612
}
13+
1714
}

CustomLegendSample/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net9.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<UseWPF>true</UseWPF>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.SfChart.WPF" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomLegendSample", "CustomLegendSample.csproj", "{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3CCAEB5F-6EA0-45F3-8320-34B305EDE66D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
<Window x:Class="Sample1.MainWindow"
1+
<Window x:Class="CustomLegendSample.MainWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="clr-namespace:Sample1"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
56
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF"
6-
Title="Sample" WindowState="Maximized"
7-
x:Name="window"
8-
Height="500" Width="725">
7+
xmlns:local="clr-namespace:CustomLegendSample"
8+
mc:Ignorable="d"
9+
Title="Sample" WindowState="Maximized" x:Name="window" Height="500" Width="725">
10+
911
<Grid x:Name="grid" Margin="10">
1012
<Grid.DataContext>
11-
<local:ViewModel x:Name="viewModel"></local:ViewModel>
13+
<local:ViewModel x:Name="viewModel"/>
1214
</Grid.DataContext>
15+
1316
<Grid.Resources>
1417
<DataTemplate x:Key="itemTemplate">
1518

1619
<StackPanel Margin="10,0,10,0" Orientation="Horizontal">
1720

1821
<CheckBox Margin="2" Tag="{Binding}"
19-
IsChecked="True"
20-
Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>
22+
IsChecked="True"
23+
Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>
2124
<Rectangle Width="{Binding IconWidth}" Height="{Binding IconHeight}"
22-
23-
Fill="{Binding Interior}" Margin="2"/>
25+
26+
Fill="{Binding Interior}" Margin="2"/>
2427

2528
<TextBlock HorizontalAlignment="Center"
26-
Margin="5,0,0,0"
27-
VerticalAlignment="Center"
28-
Text="{Binding Item.XValue}">
29+
Margin="5,0,0,0"
30+
VerticalAlignment="Center"
31+
Text="{Binding Item.XValue}">
2932

3033
</TextBlock>
31-
3234
</StackPanel>
33-
3435
</DataTemplate>
3536
</Grid.Resources>
36-
<chart:SfChart x:Name="chart">
37-
37+
38+
<chart:SfChart x:Name="chart">
3839
<local:PieSeriesExt x:Name="series1" Label="Series" XBindingPath="XValue" YBindingPath="YValue" />
3940
<local:PieSeriesExt x:Name="series2" XBindingPath="XValue" YBindingPath="YValue" />
40-
4141
</chart:SfChart>
42-
43-
</Grid>
42+
</Grid>
4443
</Window>

WPF_Sample/Sample/MainWindow.xaml.cs renamed to CustomLegendSample/MainWindow.xaml.cs

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
using Syncfusion.UI.Xaml.Charts;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Collections.ObjectModel;
5-
using System.Collections.Specialized;
6-
using System.ComponentModel;
7-
using System.Diagnostics;
8-
using System.Globalization;
9-
using System.Linq;
10-
using System.Text;
11-
using System.Threading;
12-
using System.Threading.Tasks;
13-
using System.Windows;
14-
using System.Windows.Controls;
15-
using System.Windows.Data;
16-
using System.Windows.Documents;
17-
using System.Windows.Input;
18-
using System.Windows.Media;
19-
using System.Windows.Media.Imaging;
20-
using System.Windows.Navigation;
21-
using System.Windows.Shapes;
22-
using System.Collections;
23-
using System.Reflection;
24-
25-
namespace Sample1
1+
namespace CustomLegendSample
262
{
3+
using Syncfusion.UI.Xaml.Charts;
4+
using System.Collections.ObjectModel;
5+
using System.Reflection;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
279
/// <summary>
2810
/// Interaction logic for MainWindow.xaml
2911
/// </summary>
@@ -57,7 +39,7 @@ public MainWindow()
5739

5840
legend.ItemTemplate = grid.Resources["itemTemplate"] as DataTemplate;
5941
chart.Legend = legend;
60-
42+
6143
}
6244

6345
private void CheckBox_Checked(object sender, RoutedEventArgs e)
@@ -103,44 +85,8 @@ private void UpdateArea()
10385
info?.Invoke(chart, new object[] { true });
10486
}
10587
}
106-
public class Model
107-
{
108-
public string XValue { get; set; }
109-
public double YValue { get; set; }
110-
}
111-
112-
public class ViewModel
113-
{
114-
public ViewModel()
115-
{
116-
GenerateData();
117-
}
11888

119-
public void GenerateData()
120-
{
121-
Data = new ObservableCollection<Model>();
122-
Random rd = new Random();
123-
for (int i = 0; i < 6; i++)
124-
{
125-
Data.Add(new Model()
126-
{
127-
XValue = "Label" +i.ToString(),
128-
YValue = rd.Next(0, 50)
129-
});
130-
}
131-
}
132-
133-
private ObservableCollection<Model> data;
134-
135-
public ObservableCollection<Model> Data
136-
{
137-
get { return data; }
138-
set { data = value; }
139-
}
140-
141-
}
142-
143-
public class PieSeriesExt :PieSeries
89+
public class PieSeriesExt : PieSeries
14490
{
14591
public ObservableCollection<ChartSegment> ChartSegments
14692
{
@@ -150,5 +96,4 @@ public ObservableCollection<ChartSegment> ChartSegments
15096
}
15197
}
15298
}
153-
154-
}
99+
}

CustomLegendSample/Model/Model.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CustomLegendSample
2+
{
3+
public class Model
4+
{
5+
public string XValue { get; set; }
6+
public double YValue { get; set; }
7+
}
8+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace CustomLegendSample
2+
{
3+
using System.Collections.ObjectModel;
4+
5+
public class ViewModel
6+
{
7+
public ViewModel()
8+
{
9+
GenerateData();
10+
}
11+
12+
public void GenerateData()
13+
{
14+
Data = new ObservableCollection<Model>();
15+
Random rd = new Random();
16+
for (int i = 0; i < 6; i++)
17+
{
18+
Data.Add(new Model()
19+
{
20+
XValue = "Label" + i.ToString(),
21+
YValue = rd.Next(0, 50)
22+
});
23+
}
24+
}
25+
26+
private ObservableCollection<Model> data;
27+
28+
public ObservableCollection<Model> Data
29+
{
30+
get { return data; }
31+
set { data = value; }
32+
}
33+
34+
}
35+
}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ private void UpdateArea()
9797

9898
## Output:
9999

100+
The following demo image illustrates creating custom legend items, with and without toogle functionality in WPF, following the implemented steps.
101+
100102
![custom legend without toggle wpf chart.png](custom-legend-without-toggle.png)
101103

102104
![custom legend with toggle wpf chart](custom-legend-with-toggle.png)
103105

104-
KB article - [How to create custom legend items in WPF Chart?](https://www.syncfusion.com/kb/10675/how-to-create-custom-legend-items-in-wpf-chart)
106+
## Troubleshooting
107+
108+
#### Path too long exception
109+
110+
If you are facing a path too long exception when building this example project, close Visual Studio and rename the repository to a shorter name before building the project.
111+
112+
For more details, refer to the KB on [How to create custom legend items in WPF Chart](https://www.syncfusion.com/kb/10675/how-to-create-custom-legend-items-in-wpf-chart).

0 commit comments

Comments
 (0)