'-1' is not a valid value for property 'Height'.

3 posts, 1 answers
  1. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 31 Jul 2012 Link to this post

    Hello!!

    So, I blew up your ChartView by having fun with animating heights.  In my live application, I have two ChartViews on different rows of a Grid and the row heights are animated to show/collapse a chart.  If the window size is small enough, I will get a  "'-1' is not a valid value for property 'Height'." exception with this stack trace:
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
    at System.Windows.FrameworkElement.set_Height(Double value)
    at Telerik.Windows.Controls.ChartView.PresenterBase.ArrangeUIElement(FrameworkElement presenter, RadRect layoutSlot, Boolean setSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\Common\PresenterBase.cs:line 297
    at Telerik.Windows.Controls.ChartView.CartesianChartGrid.UpdateYStripes() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\CartesianChart\CartesianChartGrid.cs:line 479
    at Telerik.Windows.Controls.ChartView.CartesianChartGrid.UpdateVisuals(ChartLayoutContext context) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\CartesianChart\CartesianChartGrid.cs:line 421
    at Telerik.Windows.Controls.ChartView.CartesianChartGrid.UpdateUICore(ChartLayoutContext context) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Visualization\CartesianChart\CartesianChartGrid.cs:line 296

    I have been able to reproduce this issue in its own project by forcefully setting the chart Height property to a small value and then adding a series (line/bar doesn't matter).  This is done in a Command executed by pressing a button.  Here is the relevant reproduction code:

    View:
    <Window x:Class="TinyChart.MainWindow"
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" Height="350" Width="525">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
        <telerik:RadCartesianChart x:Name="chart" telerik:StyleManager.Theme="Metro">
            <telerik:RadCartesianChart.TrackBallInfoStyle>
                <Style TargetType="telerik:TrackBallInfoControl">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" Foreground="Black" HorizontalAlignment="Center"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </telerik:RadCartesianChart.TrackBallInfoStyle>
            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartTrackBallBehavior ShowIntersectionPoints="True" ShowTrackInfo="True" SnapMode="AllClosePoints" />
            </telerik:RadCartesianChart.Behaviors>
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:DateTimeCategoricalAxis LabelFormat="dd MMM yyyy" Title="Date Processed" DateTimeComponent="DayOfYear" LabelFitMode="Rotate" LabelInterval="3" LastLabelVisibility="Visible">
                    <telerik:DateTimeCategoricalAxis.LabelTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding}" HorizontalAlignment="Center" />
                            </StackPanel>
                        </DataTemplate>
                    </telerik:DateTimeCategoricalAxis.LabelTemplate>
                </telerik:DateTimeCategoricalAxis>
            </telerik:RadCartesianChart.HorizontalAxis>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis Title="# Documents Processed" />
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:RadCartesianChart.Grid>
                <telerik:CartesianChartGrid MajorLinesVisibility="Y" StripLinesVisibility="Y" />
            </telerik:RadCartesianChart.Grid>
            </telerik:RadCartesianChart>
            <Button Command="{Binding MyCommand}" Width="64" Height="64" VerticalAlignment="Top" HorizontalAlignment="Right" Content="..." />
        </Grid>
    </Window>

    View Model:

    public class MainWindowViewModel
        {
            public ObservableCollection<Item> Items { get; set; }
            public ICommand MyCommand { get; set; }
            public MainWindow View { get; set; }
     
            public MainWindowViewModel()
            {
                MyCommand = new RelayCommand(OnMyCommand);
     
                Items = new ObservableCollection<Item>();
     
                Items.Add(new Item { Date = DateTime.Now, Number = 1 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(1), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(2), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(3), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(4), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(5), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(6), Number = 0 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(1), Number = 1 });
                Items.Add(new Item { Date = DateTime.Now.AddDays(7), Number = 0 });
            }
     
            private void OnMyCommand()
            {
                View.chart.Height = 100;
                View.chart.Series.Add(new BarSeries
                            {
                                //StrokeThickness = 4,
                                //Stroke = Brushes.Red,
                                ItemsSource = Items,
                                CategoryBinding = new PropertyNameDataPointBinding("Date"),
                                ValueBinding = new PropertyNameDataPointBinding("Number"),
                                ShowLabels = false
                            });
            }
        }
     
        public class Item
        {
            public DateTime Date { get; set; }
            public int Number { get; set; }
     
            public override string ToString()
            {
                return Date.ToString() + " - " + Number.ToString();
            }
        }

    I require this situation to work.  Although it may seem silly to set height before adding a series, this should not cause a crash.  If a workaround can't be found, I will require a hotfix.  This occurs with the latest version Q2 2012 SP1 (also Q1 2012).

    The series is added after user invokes a command, so I know what data to display.  There can be multiple series in a chart also, hence the programmatic approach.

    I am at a loss to figure out how to solve this problem as I can find nothing wrong with my code and it works fine when the screen size is sufficiently large enough.

    Thank you very much!
  2. Darlene
    Darlene avatar
    13 posts
    Member since:
    Jan 2012

    Posted 01 Aug 2012 Link to this post

    n/m.  I set MinHeight = 150 and put a ScrollViewer around the screen and that seems to have solved the issue.  It still shouldn't crash in this situation howeever.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 03 Aug 2012 Link to this post

    Hello,

    The issue you are reporting is indeed a bug, which I reproduced with 2012 Q2 SP1 (2012.2.725).
    Fortunately the bug is fixed in the latest internal build - 2012.2.730. 

    You can give it a try.

    Regards,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top