Hello!
I am trying to programmatically set a range for HeatmapColorPalette and attached HeatmapColorMap to min and max of my data.
Binding HeatmapColorPalette.Maximum to a property in my View Model works well. However, when I add HeatmapColorMap everything breaks, the heat map no longer responds to changes in View Model.
What am I doing wrong?
Here is my View:
<Window x:Class="SciChartHeatMap.MainWindow"
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:local="clr-namespace:SciChartHeatMap"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
d:DataContext="{d:DesignInstance Type=local:HeatMapViewModel, IsDesignTimeCreatable=True}"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.Resources>
<s:GradientStopsToLinearGradientBrushConverter x:Key="ColorsToLinearGradientBrushConverter"/>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<s:SciChartSurface Grid.Row="0" Grid.RowSpan="2">
<s:SciChartSurface.RenderableSeries>
<s:FastUniformHeatmapRenderableSeries x:Name="HeatMapSeries" DataSeries="{Binding Data}" Opacity="0.9">
<s:FastUniformHeatmapRenderableSeries.ColorMap>
<s:HeatmapColorPalette Maximum="{Binding ColorMaximum}">
<s:HeatmapColorPalette.GradientStops>
<GradientStop Offset="0" Color="DarkBlue"/>
<GradientStop Offset="0.2" Color="CornflowerBlue"/>
<GradientStop Offset="0.4" Color="DarkGreen"/>
<GradientStop Offset="0.6" Color="Chartreuse"/>
<GradientStop Offset="0.8" Color="Yellow"/>
<GradientStop Offset="1" Color="Red"/>
</s:HeatmapColorPalette.GradientStops>
</s:HeatmapColorPalette>
</s:FastUniformHeatmapRenderableSeries.ColorMap>
</s:FastUniformHeatmapRenderableSeries>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.XAxis>
<s:NumericAxis
FlipCoordinates="False"
ScientificNotation="None"
AutoTicks="False"
MajorDelta="1"
MinorDelta="0.5"
AxisAlignment="Top"/>
</s:SciChartSurface.XAxis>
<s:SciChartSurface.YAxis>
<s:NumericAxis
FlipCoordinates="True"
ScientificNotation="None"
AxisAlignment="Left"/>
</s:SciChartSurface.YAxis>
</s:SciChartSurface>
<!-- Enabling this will break the program
<s:HeatmapColorMap
Grid.Column="1"
Grid.Row="0"
Grid.RowSpan="2"
Margin="5,0,5,0"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
DataContext="{Binding Source={x:Reference Name=HeatMapSeries}, Mode=OneWay}"
ColorMap="{Binding ColorMap.GradientStops, Converter={StaticResource ColorsToLinearGradientBrushConverter}}"
Maximum="{Binding ColorMap.Maximum}"
Orientation="Vertical">
</s:HeatmapColorMap>
-->
<Label
Grid.Row="0"
Grid.Column="2"
Content="{Binding ColorMaximum}"
Width="50"
HorizontalContentAlignment="Center"/>
<Slider
Grid.Column="2"
Grid.Row="1"
Orientation="Vertical"
Minimum="0"
Maximum="10"
HorizontalAlignment="Center"
Value="{Binding ColorMaximum}"/>
</Grid>
The idea in this small example is for slider to control both HeatmapColorPalette.Maximum and s:HeatmapColorMap.Maximum
The code in my View Model is pretty simple:
private double mColorMax;
public double ColorMaximum
{
get => mColorMax;
set
{
mColorMax = value;
OnPropertyChanged();
}
}
My View Model implements INotifyPropertyChanged
I will appreciate any suggestions.
Thank you in advance!
- You must login to post comments
Hi Alex,
I am sorry for the late reply.
I have investigated your sample project. The issue is caused by incorrect Bindings in your application. OneWay binding is replaced by value if the Property is modified by anything but the Binding Source. For more info please take a look at the “Direction of the Data Flow” of the following documentation:
https://docs.microsoft.com/ru-ru/dotnet/api/system.windows.data.binding.mode?view=netframework-4.8
I have modified Binding Mode for HeatmapColorPalette.Maximum, HeatmapColorMap.Maximum and Slider.Value properties in the MainWindow.xaml file in the sample project you’ve provided. Please find it attached.
- Oleksandr Shvets answered 5 years ago
- You must login to post comments
Please login first to submit.