首页 新闻 搜索 专区 学院

求教这段WPF中嵌入Flash的代码哪里出问题了???

0
悬赏园豆:40 [已关闭问题] 关闭于 2012-03-23 16:50

 为什么使用底下这种动态添加控件的方式来嵌入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";

Lonely Bandit的主页 Lonely Bandit | 初学一级 | 园豆:85
提问于:2012-02-29 15:57
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册