为什么使用底下这种动态添加控件的方式来嵌入Flash会出现问题??
//创建一个边框(最外层)
Border borderBody = new Border();
borderBody.Background = Brushes.Transparent;
borderBody.BorderBrush = Brushes.White;
borderBody.BorderThickness = new Thickness(5);
//创建一个滚动条(放到最外层边框去)
ScrollViewer scroll = new ScrollViewer();
scroll.Width = 1160;
scroll.Height = 104;
scroll.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
scroll.Background = Brushes.Transparent;
borderBody.Child = scroll; //放到边框去
//创建一个StackPanel容器用来保存具体元素(放到滚动条内)
StackPanel sp = new StackPanel();
sp.Height = 104;
sp.Orientation = Orientation.Horizontal;
scroll.Content = sp; //放到滚动条去
//具体元素放到StackPanel
for (int i = 0; i < 100; i++)
{
Border border = new Border();
border.BorderBrush = Brushes.White;
border.BorderThickness = new Thickness(2);
border.Width = 100;
border.Height = 75;
WindowsFormsHost formHost = new WindowsFormsHost();
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
formHost.Child = axShockwaveFlash;
border.Child = formHost;
//出错
//引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常。
axShockwaveFlash.Movie = @"E:\game.swf";
sp.Children.Add(border);
}
//最后将最外层边框添加到界面去
grid.Children.Add(borderBody);
奇怪的是为什么这样就不会出问题
StackPanel sp = new StackPanel();
Border border = new Border();
border.BorderBrush = Brushes.White;
border.BorderThickness = new Thickness(2);
border.Width = 100;
border.Height = 75;
WindowsFormsHost formHost = new WindowsFormsHost();
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
formHost.Child = axShockwaveFlash;
border.Child = formHost;
sp.Children.Add(border);
grid.Children.Add(sp);
axShockwaveFlash.Movie = @"E:\game.swf";
------解决方案--------------------
好像wpf加入activex控件 窗口不能设透明