我能够让其他Form控件在WPF中工作,但我似乎无法使用Chart控件将自身显示为除白色矩形之外的任何其他内容。
我尝试在XAML中使用WindowsFormsHost
<WindowsFormsHost Grid.Row="0" Grid.ColumnSpan="7" Margin="4">
<dv:Chart x:Name="chart"/>
</WindowsFormsHost>
我还创建了UserControl
public partial class ChartUserControl : UserControl
{
public ChartUserControl()
{
InitializeComponent();
createSomethingToSee();
}
private void createSomethingToSee()
{
chart.Series.Clear();
var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
{
Name = "Series1",
Color = System.Drawing.Color.Green,
IsVisibleInLegend = false,
IsXValueIndexed = true,
ChartType = SeriesChartType.Line
};
this.chart.Series.Add(series1);
for (int i = 0; i < 100; i++)
{ series1.Points.AddXY(i, i); }
chart.Invalidate();
}
}
在我的窗口中,我使用两种方法,没有显示
<my:ChartUserControl HorizontalAlignment="Left" x:Name="chartUserControl1" VerticalAlignment="Top" />
<my:MyChart Grid.Row="1" Height="249" HorizontalAlignment="Left" Margin="0,1,0,0" x:Name="myChart1" VerticalAlignment="Top" Width="633" />
在WPF中使用Chart有没有运气?可能吗?我错过了什么?