本文介绍了在Flash中嵌入WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我很难在WPF应用程序中嵌入Flash动画。我尝试了很多事情,只有一个实际上为我工作。



我找到了一个解决方案,所以我会张贴在下面。解决方案我找到了解决方案,我遵循本教程,将C#转换为VB:进行通信

但最后,我设法最终只有30行代码来做我想要的东西...



以下是来自WinForm用户控件的代码 WFFlashPlayer.vb

$ $ p $ 导入System.Windows.Forms

命名空间FlashAxControls
部分公共类WFFlashPlayer
继承UserControl
Public Sub New()
InitializeComponent()
AxShockwaveFlash.Bas e =#
AxShockwaveFlash.Movie =#
End Sub
End Class
End命名空间
WFFlashPlayer.Designer.vb :

 命名空间FlashAxControls 
部分类WFFlashPlayer
'''< summary>
'''必需的设计变量。
'''< / summary>
Private Component As System.ComponentModel.IContainer = Nothing

'''< summary>
'''清理所有正在使用的资源。
'''< / summary>
'''< param name =disposing>如果管理的资源应该被丢弃,则为true;否则为false。< / param>
受保护的覆盖Sub Dispose(配置为布尔值)
如果处理AndAlso(组件IsNot Nothing)则
components.Dispose()
End If
MyBase.Dispose(disposing )
End Sub

#RegionComponent Designer generated code

'''< summary>
'''Designer支持的必需方法 - 不要用代码编辑器修改
'''这个方法的内容。
'''< / summary>
Private Sub InitializeComponent()
Dim resource As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(WFFlashPlayer))
Me.AxShockwaveFlash = New AxShockwaveFlashObjects.AxShockwaveFlash()
CType(Me.AxShockwaveFlash,System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'AxShockwaveFlash
'
Me.AxShockwaveFlash .Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom或System.Windows.Forms.AnchorStyles.Left)_
或System.Windows.Forms.AnchorStyles.Right),System.Windows.Forms。 AnchorStyles)
Me.AxShockwaveFlash.Enabled = True
Me.AxShockwaveFlash.Location = New System.Drawing.Point(0,0)
Me.AxShockwaveFlash.Margin = New System.Windows.Forms .Padding(0)
Me.AxShockwaveFlash.Name =A xShockwaveFlash
Me.AxShockwaveFlash.OcxState = CType(resources.GetObject(AxShockwaveFlash.OcxState),System.Windows.Forms.AxHost.State)
Me.AxShockwaveFlash.Size = New System.Drawing。大小(1125,825)
Me.AxShockwaveFlash.TabIndex = 0
'
'WFFlashPlayer
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0! ,13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.FromArgb(CType(239,Byte),Integer),CType (CType(239,Byte),Integer),CType(CType(242,Byte),Integer))
Me.Controls.Add(Me.SimpleButton1)
Me.Controls.Add(Me.AxShockwaveFlash )
Me.Name =WFFlashPlayer
Me.Size = New System.Drawing.Size(1125,825)
CType(Me.AxShockwaveFlash,System.ComponentModel.ISupportInitialize).EndInit )
Me.ResumeLayout(False)
End Sub

#End Region

专用AxShockwaveFlash As AxShockwaveFlashObjects.AxShockwaveFlash
结束类
结束命名空间

这里是WPF用户控件, FlashPlayer.xaml.vb

  Imports System.Windows.Forms.Integration 

命名空间FlashAxControls
部分公共类FlashPlayer
继承UserControl
$ b $ Private Sub FlashPlayer_Loaded(sender As Object,e As RoutedEventArgs)
Dim host As New WindowsFormsHost()
Dim player As New WFFlashPlayer()

host.Child = player
FlashPlayerGrid.Children.Add(host)
End Sub
End Class
End命名空间

FlashPlayer.xaml

 < UserControl x:Class =FlashAxControls.FlashPlayer
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
xmlns :mc =http://schemas.openxmlformats.org/markup-compatibility/2006
xmlns:d =http://schemas.microsoft.com/expression/blend/2008
mc :Ignorable =d
d:DesignHeight =300d:DesignWidth =300Loaded =FlashPlayer_Loaded>
< Grid x:Name =FlashPlayerGrid>

< / Grid>
< / UserControl>

最后,这是我的WPF应用程序XAML代码(有点定制):

 < dxr:DXRibbonWindow x:Class =MyProject.MainWindow
xmlns =http://schemas.microsoft.com/winfx/ 2006 / xaml / presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
xmlns:dx =http://schemas.devexpress.com/ winfx / 2008 / xaml / core
xmlns:dxb =http://schemas.devexpress.com/winfx/2008/xaml/bars
xmlns:dxr =http:// schemas。 devexpress.com/winfx/2008/xaml/ribbon
xmlns:dxe =http://schemas.devexpress.com/winfx/2008/xaml/editors
xmlns:controls =clr-命名空间:FlashAxControls.FlashAxControls; assembly = FlashAxControls
Title =MainWindowHeight =922Width =1127Background =#FFEFEFF2ResizeMode =CanMinimizeBorderEffect =DefaultIsAeroMode =False DisplayShowModeSelector =FalseWindowStyle =SingleBorderWindowShowInTaskbar =True>
<网格>
< Grid Horizo​​ntalAlignment =LeftGrid.Row =1Grid.ColumnSpan =2>
< controls:FlashPlayer Height =825Width =1125/>
< / Grid>
< / Grid>
< / dxr:DXRibbonWindow>

我希望这可以帮助别人。


Okay, so I had trouble to embed a Flash animation in a WPF application. I tried many things and only one actually worked for me.

I found a solution, so I'll post it below.

解决方案

I found the solution, I followed this tutorial, converting C# to VB: http://blogs.microsoft.co.il/janiv/2009/09/20/embedding-and-communicating-with-the-macromedia-flash-player-in-wpf/

But at the end, I managed to end up with only 30 lines of code to do what I wanted at first...

Here's the code from WinForm User Control, WFFlashPlayer.vb :

Imports System.Windows.Forms

Namespace FlashAxControls
    Partial Public Class WFFlashPlayer
        Inherits UserControl
        Public Sub New()
            InitializeComponent()
            AxShockwaveFlash.Base = "#"
            AxShockwaveFlash.Movie = "#"
        End Sub
    End Class
End Namespace

In case, WFFlashPlayer.Designer.vb :

Namespace FlashAxControls
    Partial Class WFFlashPlayer
        ''' <summary>
        ''' Required designer variable.
        ''' </summary>
        Private components As System.ComponentModel.IContainer = Nothing

        ''' <summary>
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Overrides Sub Dispose(disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Component Designer generated code"

        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(WFFlashPlayer))
            Me.AxShockwaveFlash = New AxShockwaveFlashObjects.AxShockwaveFlash()
            CType(Me.AxShockwaveFlash, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'AxShockwaveFlash
            '
            Me.AxShockwaveFlash.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
            Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
            Me.AxShockwaveFlash.Enabled = True
            Me.AxShockwaveFlash.Location = New System.Drawing.Point(0, 0)
            Me.AxShockwaveFlash.Margin = New System.Windows.Forms.Padding(0)
            Me.AxShockwaveFlash.Name = "AxShockwaveFlash"
            Me.AxShockwaveFlash.OcxState = CType(resources.GetObject("AxShockwaveFlash.OcxState"), System.Windows.Forms.AxHost.State)
            Me.AxShockwaveFlash.Size = New System.Drawing.Size(1125, 825)
            Me.AxShockwaveFlash.TabIndex = 0
            '
            'WFFlashPlayer
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(239, Byte), Integer), CType(CType(239, Byte), Integer), CType(CType(242, Byte), Integer))
            Me.Controls.Add(Me.SimpleButton1)
            Me.Controls.Add(Me.AxShockwaveFlash)
            Me.Name = "WFFlashPlayer"
            Me.Size = New System.Drawing.Size(1125, 825)
            CType(Me.AxShockwaveFlash, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
        End Sub

#End Region

        Private AxShockwaveFlash As AxShockwaveFlashObjects.AxShockwaveFlash
    End Class
End Namespace

Here's the WPF User Control, FlashPlayer.xaml.vb :

Imports System.Windows.Forms.Integration

Namespace FlashAxControls
    Partial Public Class FlashPlayer
        Inherits UserControl

        Private Sub FlashPlayer_Loaded(sender As Object, e As RoutedEventArgs)
            Dim host As New WindowsFormsHost()
            Dim player As New WFFlashPlayer()

            host.Child = player
            FlashPlayerGrid.Children.Add(host)
        End Sub
    End Class
End Namespace

FlashPlayer.xaml :

<UserControl x:Class="FlashAxControls.FlashPlayer"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         mc:Ignorable="d"
         d:DesignHeight="300" d:DesignWidth="300" Loaded="FlashPlayer_Loaded">
    <Grid x:Name="FlashPlayerGrid">

    </Grid>
</UserControl>

Finally, here's my WPF application XAML code (a bit customized) :

<dxr:DXRibbonWindow x:Class="MyProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
        xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:controls="clr-namespace:FlashAxControls.FlashAxControls;assembly=FlashAxControls"
        Title="MainWindow" Height="922" Width="1127" Background="#FFEFEFF2" ResizeMode="CanMinimize" BorderEffect="Default" IsAeroMode="False" DisplayShowModeSelector="False" WindowStyle="SingleBorderWindow" ShowInTaskbar="True">
    <Grid>
        <Grid HorizontalAlignment="Left" Grid.Row="1" Grid.ColumnSpan="2">
            <controls:FlashPlayer Height="825" Width="1125"/>
        </Grid>
    </Grid>
</dxr:DXRibbonWindow>

I hope this can help someone.

这篇关于在Flash中嵌入WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 02:25