Skip to content

Commit a0990d8

Browse files
Merge pull request #1 from SyncfusionExamples/895079-HearingRangeDemo
Task-895079 Prepared the WPF range bar sample for hearing range
2 parents 3ab6c17 + 61bfd15 commit a0990d8

File tree

12 files changed

+334
-2
lines changed

12 files changed

+334
-2
lines changed

HearingRangeDemo/HearingRangeDemo.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34728.123
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HearingRangeDemo", "HearingRangeDemo\HearingRangeDemo.csproj", "{C8A64668-9BD9-433E-97FF-B9BB045CBE33}"
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+
{C8A64668-9BD9-433E-97FF-B9BB045CBE33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C8A64668-9BD9-433E-97FF-B9BB045CBE33}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C8A64668-9BD9-433E-97FF-B9BB045CBE33}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C8A64668-9BD9-433E-97FF-B9BB045CBE33}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {401AF6A4-894A-4DC8-99C7-7019A6EB9326}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="HearingRangeDemo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:HearingRangeDemo"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Configuration;
2+
using System.Data;
3+
using System.Windows;
4+
5+
namespace HearingRangeDemo
6+
{
7+
/// <summary>
8+
/// Interaction logic for App.xaml
9+
/// </summary>
10+
public partial class App : Application
11+
{
12+
}
13+
14+
}
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
using System.Windows.Media;
9+
10+
namespace HearingRangeDemo
11+
{
12+
public class ValueToRangeConverter : IValueConverter
13+
{
14+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
if (value is string textValue && double.TryParse(textValue, out double position))
17+
{
18+
string text;
19+
if (position >= 1000 && position <= 180000)
20+
{
21+
text = (position / 1000).ToString("N0");
22+
text = $"{text}kHz";
23+
}
24+
else
25+
{
26+
text = $"{position:N0}Hz";
27+
}
28+
return text;
29+
}
30+
31+
return null;
32+
}
33+
34+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
35+
{
36+
return value;
37+
}
38+
}
39+
}
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>net8.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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
<ItemGroup>
5+
<ApplicationDefinition Update="App.xaml">
6+
<SubType>Designer</SubType>
7+
</ApplicationDefinition>
8+
</ItemGroup>
9+
<ItemGroup>
10+
<Page Update="MainWindow.xaml">
11+
<SubType>Designer</SubType>
12+
</Page>
13+
</ItemGroup>
14+
</Project>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<Window x:Class="HearingRangeDemo.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:HearingRangeDemo"
7+
mc:Ignorable="d"
8+
xmlns:chart="clr-namespace:Syncfusion.UI.Xaml.Charts;assembly=Syncfusion.SfChart.WPF">
9+
10+
<Window.DataContext>
11+
<local:HearingRangeData/>
12+
</Window.DataContext>
13+
14+
<Window.Resources>
15+
<local:ValueToRangeConverter x:Key="valueToRangeConverter"/>
16+
</Window.Resources>
17+
18+
<Border Margin="30" Padding="10,10,50,20" BorderThickness="2" CornerRadius="10" BorderBrush="#b0b8bf">
19+
<chart:SfChart HorizontalHeaderAlignment="Left" >
20+
21+
<chart:SfChart.Header>
22+
<Grid Margin="0,0,0,10">
23+
<Grid.ColumnDefinitions>
24+
<ColumnDefinition Width="13"/>
25+
<ColumnDefinition Width="*"/>
26+
</Grid.ColumnDefinitions>
27+
<StackPanel Orientation="Vertical" Margin="0,5,0,0" Background="#2582a4"/>
28+
<StackPanel Grid.Column="1" Margin="3,0,0,0">
29+
<TextBlock Text="Hearing Range Among Different Living Beings" FontSize="25" FontWeight="SemiBold" Foreground="Black"/>
30+
<TextBlock Text="Frequency Spectrum from Hertz (Hz) to Kilohertz (kHz)" FontSize="18" Foreground="Gray"/>
31+
</StackPanel>
32+
</Grid>
33+
</chart:SfChart.Header>
34+
35+
<chart:SfChart.PrimaryAxis>
36+
<chart:CategoryAxis AutoScrollingMode="End" AutoScrollingDelta="13" ShowGridLines="False" Interval="1"
37+
LabelPlacement="BetweenTicks">
38+
<chart:CategoryAxis.LabelStyle>
39+
<chart:LabelStyle FontSize="12"/>
40+
</chart:CategoryAxis.LabelStyle>
41+
</chart:CategoryAxis>
42+
</chart:SfChart.PrimaryAxis>
43+
44+
<chart:SfChart.SecondaryAxis>
45+
<chart:NumericalAxis Minimum="-10000" Maximum="180000" ShowGridLines="False"
46+
LabelCreated="LabelCreated">
47+
<chart:NumericalAxis.LabelStyle>
48+
<chart:LabelStyle FontSize="12"/>
49+
</chart:NumericalAxis.LabelStyle>
50+
</chart:NumericalAxis>
51+
</chart:SfChart.SecondaryAxis>
52+
53+
<chart:SfChart.Behaviors>
54+
<chart:ChartZoomPanBehavior EnablePinchZooming="False" ResetOnDoubleTap="False" EnablePanning="True" EnableMouseWheelZooming="False"/>
55+
</chart:SfChart.Behaviors>
56+
57+
<chart:RangeColumnSeries ItemsSource="{Binding Data}" High="HighValue" Low="LowValue" XBindingPath="LivingBeings"
58+
IsTransposed="True" SegmentSpacing="0.9">
59+
60+
<chart:RangeColumnSeries.Interior>
61+
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
62+
<GradientStop Color="#2582a4" Offset="0"/>
63+
<GradientStop Color="#ae3de0" Offset="0.5"/>
64+
<GradientStop Color="#292F2E" Offset="1"/>
65+
</LinearGradientBrush>
66+
</chart:RangeColumnSeries.Interior>
67+
68+
<chart:RangeColumnSeries.AdornmentsInfo>
69+
<chart:ChartAdornmentInfo ShowLabel="True" AdornmentsPosition="TopAndBottom" Background="Transparent" LabelPosition="Outer"
70+
ShowMarker="True" Symbol="VerticalLine">
71+
<chart:ChartAdornmentInfo.LabelTemplate>
72+
<DataTemplate>
73+
<Label Content="{Binding Converter={StaticResource valueToRangeConverter}}" FontSize="10"/>
74+
</DataTemplate>
75+
</chart:ChartAdornmentInfo.LabelTemplate>
76+
</chart:ChartAdornmentInfo>
77+
</chart:RangeColumnSeries.AdornmentsInfo>
78+
</chart:RangeColumnSeries>
79+
80+
</chart:SfChart>
81+
</Border>
82+
</Window>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Syncfusion.UI.Xaml.Charts;
2+
using System.Text;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Data;
6+
using System.Windows.Documents;
7+
using System.Windows.Input;
8+
using System.Windows.Media;
9+
using System.Windows.Media.Imaging;
10+
using System.Windows.Navigation;
11+
using System.Windows.Shapes;
12+
13+
namespace HearingRangeDemo
14+
{
15+
/// <summary>
16+
/// Interaction logic for MainWindow.xaml
17+
/// </summary>
18+
public partial class MainWindow : Window
19+
{
20+
public MainWindow()
21+
{
22+
InitializeComponent();
23+
}
24+
25+
private void LabelCreated(object sender, LabelCreatedEventArgs e)
26+
{
27+
double position = e.AxisLabel.Position;
28+
if (position >= 1000 && position <= 180000)
29+
{
30+
string text = (position / 1000).ToString("N0");
31+
e.AxisLabel.LabelContent = $"{text}kHz";
32+
}
33+
else
34+
{
35+
e.AxisLabel.LabelContent = $"{position:N0}Hz";
36+
}
37+
}
38+
}
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace HearingRangeDemo
2+
{
3+
public class HearingRangeModel
4+
{
5+
public string LivingBeings { get; set; }
6+
public double HighValue { get; set; }
7+
public double LowValue { get; set; }
8+
9+
public HearingRangeModel(string livingBeings, double highValue, double lowValue)
10+
{
11+
LivingBeings = livingBeings;
12+
HighValue = highValue;
13+
LowValue = lowValue;
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)