加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

详解WPF中Flash的嵌入的两种方式

发布时间:2020-12-15 18:09:05 所属栏目:百科 来源:网络整理
导读:XAML 方法 打开MainWindow.xaml,加入命名空间xmlns:f="clr-namespace:AxShockwaveFlashObjects;assembly=AxInterop.ShockwaveFlashObjects"。在中加入WindowsFormsHost 用于调用WinForm 程序,并在其中添加AxShockwaveFlash 控件加载Flash 文件。 ? Window
XAML 方法

  打开MainWindow.xaml,加入命名空间xmlns:f="clr-namespace:AxShockwaveFlashObjects;assembly=AxInterop.ShockwaveFlashObjects"。在中加入WindowsFormsHost 用于调用WinForm 程序,并在其中添加AxShockwaveFlash 控件加载Flash 文件。

?

<Window x:Class="WpfFlash.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:f="clr-namespace:AxShockwaveFlashObjects;assembly=AxInterop.ShockwaveFlashObjects"
        Title="Crab Shooter" Height="540" Width="655">
    <Grid>
        <WindowsFormsHost>
            <f:AxShockwaveFlash x:Name="flashShow"/>
        </WindowsFormsHost>
    </Grid>
</Window>


打开MainWindow.xaml.cs 将Flash 文件加载到flashShow 控件。

using System;
using System.Windows;

namespace WpfFlash
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            string flashPath = Environment.CurrentDirectory;
            flashPath += @"game.swf";
            flashShow.Movie = flashPath;
        }
    }
}


C# 方法

  使用C# 实现相同的效果,首先将XAML 代码按如下方式修改,在Window 中加入Loaded 事件。

<Window x:Class="WpfFlash.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Crab Shooter" Loaded="FlashLoaded" Height="540" Width="655">
    <Grid x:Name="mainGrid"/>
</Window>


定义FlashLoaded 方法,主要通过WindowsFormsHost和 AxShockwaveFlash 完成Flash 加载操作。

using System;
using System.Windows;
using System.Windows.Forms.Integration;
using AxShockwaveFlashObjects;

namespace WpfFlash
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void FlashLoaded(object sender,RoutedEventArgs e)
        {
            WindowsFormsHost formHost = new WindowsFormsHost();

            AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();

            formHost.Child = axShockwaveFlash;

            mainGrid.Children.Add(formHost);

            string flashPath = Environment.CurrentDirectory;
            flashPath += @"game.swf";
            
            axShockwaveFlash.Movie = flashPath;
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读