2

我在显示自定义控件时遇到了一些问题。当页面加载时它是不可见的,但是一旦我调整窗口大小它就会出现。

这是我正在使用的代码:

<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>

我使用的 customc 控件是来自 amCharts(amCharts 网站)的 StockChart。

提前致谢!

杰伦·科西乌斯

更新 1: 因此包含自定义控件的 Grid 的宽度和高度为“NaN”。为 Grid 设置宽度和高度不会改变任何内容。

更新 2: 我尝试通过执行以下操作之一来触发图表刷新:

  • base.InvalidateVisual();
  • base.UpdateLayout();
  • 网格.UpdateLayout();
  • grid.InvalidateVisual();
  • 图表.Focus();
  • Chart.UpdateLayout();
  • Chart.InvalidateVisual();
  • 图表.刷新();

一切都没有任何结果。

更新 3: 在按钮单击事件上执行Chart.Refresh();时,图表会显示。

4

3 回答 3

2

尝试在图表上添加以下事件:Loaded="Chart_Loaded",在事件处理程序中添加以下规则:Chart.Refresh();

祝你好运!

于 2012-04-05T14:02:50.627 回答
2

使用snoop检查可视化树并查看树损坏的位置。

于 2012-04-05T14:18:02.287 回答
0

确保自定义控件或包含它的东西没有将 minwidth 设置为零。当 studio 或 blend 添加 minwidth=0 作为默认值时,我在 Silverlight 中发生的情况完全相同。

于 2012-04-05T14:18:08.697 回答