If I dynamically add a Chart to a DialogWindow and minimize & restore the window, the chart disappears.
Repro Steps:
1) App starts with window in normalized state. 2) Minimize the window.3) Maximize the window. Notice chart is gone, but Legend still exists.4) Normalize the window. Notice now the chart is completely gone.
It looks like it only happens when using the separate MinimizedPanel for the window, but I'm not positive. Any suggestions on workarounds? Also, can you try against the service release build and see if it happens there too? I really want to be able to offer the charts in windows for my app.
Thanks,Keith
Repro XAML:
<UserControl x:Class="WindowingTest.ChartWindowTest" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="300" Width="300"> <Grid > <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="50" /> </Grid.RowDefinitions> <Canvas Grid.Row="0" x:Name="CanvasWindows" /> <StackPanel Grid.Row="1" x:Name="PanelMinimized" Orientation="Horizontal" /> </Grid></UserControl>
Code Behind:
void ChartWindowTest_Loaded(object sender, RoutedEventArgs e){ var data = new List<KeyValuePair<string, int>>(); data.Add(new KeyValuePair<string, int>("Category 1", 50)); data.Add(new KeyValuePair<string, int>("Category 2", 100)); data.Add(new KeyValuePair<string, int>("Category 3", 20)); data.Add(new KeyValuePair<string, int>("Category 4", 80));
var chart = new XamWebChart(); var series = new Series() { ChartType = ChartType.Bar, DataMapping = "Value = Value;Label = Key", DataSource = data }; chart.Series.Add(series);
var window = new XamWebDialogWindow() { Content = chart, MinimizedPanel = this.PanelMinimized, Header = "Chart", Width = 200, Height = 200, };
this.CanvasWindows.Children.Add(window);}
I've narrowed down the repro to just the following XAML:
<Grid > <igWindow:XamWebDialogWindow Height="200" Width="200" > <igWindow:XamWebDialogWindow.Content> <igChart:XamWebChart> <igChart:XamWebChart.Series> <igChart:Series ChartType="Column" Label="Series 1"> <igChart:Series.DataPoints> <igChart:DataPoint Value="10" Label="point1" /> <igChart:DataPoint Value="20" Label="point2" /> </igChart:Series.DataPoints> </igChart:Series> </igChart:XamWebChart.Series> </igChart:XamWebChart> </igWindow:XamWebDialogWindow.Content> </igWindow:XamWebDialogWindow></Grid>
Steps:
1. App loads with normal window2. Maximize the window. Note chart disappears, only legend remains.3. Normalize the window. Legend disappears as well, even if you maximize again.
This uses a column chart which seems to be the easiest to repro with, but I've seen it with Pie and other chart types as well. You can also make it happen without the 200x200 if you play around resizing, etc.
I tried setting min width/height on the chart. Toggling RefreshEnabled, manually calling Refresh(true) in SizeChanged. Nothing seemed to help. The window is resizing the chart correctly, since the Chart's SizeChanged event is firing. But I can't seem to get in there and make the chart show up.
I found a workaround, by recreating the chart when the window resizes. I use a DispatcherTimer to delay things a little to limit the times the chart has to be recreated. I had to set RefreshEnabled to false in the Chart Loaded handler, since setting it when I create caused the chart to not render correctly. Seems to work pretty well, but obviously I'd prefer to not have to pay the expense all the time.
Here's the code in case anyone else is hitting this:
XAML:-------
<Grid > <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="50" /> </Grid.RowDefinitions> <Canvas Grid.Row="0" x:Name="CanvasWindows" /> <StackPanel Grid.Row="1" x:Name="PanelMinimized" Orientation="Horizontal" /> </Grid>
Code behind:--------------
public partial class ChartWindowTest : UserControl{ DispatcherTimer chartTimer; private XamWebDialogWindow chartWindow; private List<KeyValuePair<string, int>> data;
public ChartWindowTest() { InitializeComponent(); this.Loaded += new RoutedEventHandler(ChartWindowTest_Loaded); this.chartTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.5) }; this.chartTimer.Tick += ((s, e) => { CreateChart(null); this.chartTimer.Stop(); }); }
void ChartWindowTest_Loaded(object sender, RoutedEventArgs e) { data = new List<KeyValuePair<string, int>>(); data.Add(new KeyValuePair<string, int>("Category 1", 50)); data.Add(new KeyValuePair<string, int>("Category 2", 100)); data.Add(new KeyValuePair<string, int>("Category 3", 20)); data.Add(new KeyValuePair<string, int>("Category 4", 80)); data.Add(new KeyValuePair<string, int>("Category 5", 50)); data.Add(new KeyValuePair<string, int>("Category 6", 100)); data.Add(new KeyValuePair<string, int>("Category 7", 20)); data.Add(new KeyValuePair<string, int>("Category 8", 80));
chartWindow = new XamWebDialogWindow() { MinimizedPanel = this.PanelMinimized, Header = "Chart", Width = 200, Height = 200, }; chartWindow.SizeChanged += new SizeChangedEventHandler(chartWindow_SizeChanged);
this.CanvasWindows.Children.Add(chartWindow); }
void chartWindow_SizeChanged(object sender, SizeChangedEventArgs e) { var window = sender as XamWebDialogWindow; if (window == null || window.WindowState == Infragistics.Silverlight.WindowState.Minimized || window.WindowState == Infragistics.Silverlight.WindowState.Hidden ) return;
// Fire on timer. if (!this.chartTimer.IsEnabled) chartTimer.Start(); }
void CreateChart(object objectState) { var chart = new XamWebChart(); var series = new Series() { ChartType = ChartType.Bar, DataMapping = "Value = Value;Label = Key", DataSource = data }; chart.Series.Add(series); chart.Loaded += new RoutedEventHandler(chart_Loaded);
this.chartWindow.Content = chart; } void chart_Loaded(object sender, RoutedEventArgs e) { var chart = sender as XamWebChart; if (chart != null) chart.RefreshEnabled = false; }}