Вопрос

I'am having some trouble displaying a custom-control. When the page loads it's not visible, but as soon as I resize the window it appears.

Here's the code I'm using:

<UserControl x:Class="KinectBewegingsanalyse.View.UserAnalysisChartView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:c="http://schemas.amcharts.com/stock/wpf/2009/xaml"
         mc:Ignorable="d"
         d:DesignWidth="800" d:DesignHeight="600">

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

<Grid>
    <c:StockChart Name="test" Visibility="Visible" PeriodSelectorVisibility="Hidden" IsEquallySpaced="False" Margin="12">
        <c:StockChart.Charts>
            <c:Chart PlotAreaBorderBrush="{StaticResource TassBlue}" PlotAreaBorderThickness="1">
                <c:Chart.DateTimeAxis>
                    <c:DateTimeAxis ValuesEnabled="True" Stroke="Transparent" StrokeThickness="0" />
                </c:Chart.DateTimeAxis>
                <c:Chart.LeftValueAxis>
                    <c:ValueAxis ValuesFormatString="0°" Stroke="Transparent" StrokeThickness="0" />
                </c:Chart.LeftValueAxis>
                <c:Chart.Graphs>
                    <c:Graph GraphType="Line" BulletType="RoundOutline" BulletSize="8" LegendItemType="Value" LegendValueLabelText="Gemeten waarde: " LegendValueFormatString="0°" LegendPeriodItemType="Value" />
                </c:Chart.Graphs>

                <c:Chart.Legend>
                    <c:Legend PositiveValueForeground="Black" NegativeValueForeground="Black" IsDateVisible="True" HideDateOnPeriod="False" />
                </c:Chart.Legend>
            </c:Chart>
        </c:StockChart.Charts>

        <c:StockChart.DataSets>
            <c:DataSet Brush="{StaticResource TassMagenta}" ItemsSource="{Binding PerformedAnalysis}" DateMemberPath="Date" ValueMemberPath="Angle" />
        </c:StockChart.DataSets>
    </c:StockChart>
</Grid>

The customc control I'm using is a StockChart from amCharts (amCharts website).

Thanks in advance!

Jeroen Corsius

Update 1: So the Grid containing custom control has a width and height of 'NaN'. Settings an width and height for the Grid doesn't change anything.

Update 2: I tried to trigger an refresh for the chart by doing one of the following:

  • base.InvalidateVisual();
  • base.UpdateLayout();
  • grid.UpdateLayout();
  • grid.InvalidateVisual();
  • Chart.Focus();
  • Chart.UpdateLayout();
  • Chart.InvalidateVisual();
  • Chart.Refresh();

All without any result.

Update 3: When performing Chart.Refresh(); on a Button Click-event, the Chart shows up.

Это было полезно?

Решение

Try adding the following event on your chart: Loaded="Chart_Loaded", add the following rule in the event handler: Chart.Refresh();.

Good luck!

Другие советы

Use snoop to inspect the visual tree and see where the tree is broken.

Make sure that you don't have minwidth set to zero by either the custom control or the thing containing it. Exactly the same happened to me in Silverlight when studio or blend added minwidth=0 as a default.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top