Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MMC管理单元中的WPF_Wpf_Mmc - Fatal编程技术网

MMC管理单元中的WPF

MMC管理单元中的WPF,wpf,mmc,Wpf,Mmc,有人能提供一些在自定义MMC管理单元中使用WPF的示例代码吗?我是WPF新手,我已经了解了编写MMC管理单元的示例,但我不知道如何选择WPF而不是Winforms。我刚刚花了一上午的时间为我正在进行的一个项目构建了这个确切的场景。以下是代码的上下文无关版本: /// <summary> /// Defines a scope node with a default Forms view that will host a /// WPF control. /// </summar

有人能提供一些在自定义MMC管理单元中使用WPF的示例代码吗?我是WPF新手,我已经了解了编写MMC管理单元的示例,但我不知道如何选择WPF而不是Winforms。

我刚刚花了一上午的时间为我正在进行的一个项目构建了这个确切的场景。以下是代码的上下文无关版本:

/// <summary>
/// Defines a scope node with a default Forms view that will host a
/// WPF control.
/// </summary>
public class WPFScopeNode: ScopeNode
{
    /// <summary>
    /// Instantiates a new specialized scope node.
    /// </summary>
    public WPFScopeNode()
        : base()
    {
        this.DisplayName = "Name in tree view";

        // TODO: Create any child scope nodes, adding them to 'this.Children'.

        // Attach a forms view to this node that hosts a WPF control.
        var wpfFormView = new FormViewDescription
        {
            DisplayName = "Name of view",
            ControlType = typeof(WPFHostControl),
            ViewType = typeof(WPFHostFormView)
        };
        this.ViewDescriptions.Add(wpfFormView );
    }
}


/// <summary>
/// This class provides a model-interface for the hosted WPF control.
/// </summary>
public class WPFHostFormView : FormView
{
    public WPFHostFormView ()
    {
        this.DescriptionBarText = "WPF Host View";
    }

    /// <summary>
    /// Defines the structure of the form view.
    /// </summary>
    /// <param name="status"></param>
    protected override void OnInitialize(AsyncStatus status)
    {
        base.OnInitialize(status);

        // TODO: This may be a good place to pass 'this.Control' the
        // data context that will be used for databinding by the WPF
        // control.  Note that 'this.Control' is the Windows Forms
        // UserControl that contains an ElementHost which, in turn,
        // hosts the WPF UserControl of interest.
    }
}


/// <summary>
/// Defines a Windows Forms control that hosts a specific WPF UserControl.
/// Note the logic for automatic resizing to the parent surface in the
/// MMC MDI interface.
/// Also, 'MyWPFUserControl' is just a standard WPF
/// UserControl; nothing special needs to be done there for MMC integration.
/// </summary>
public partial class WPFHostControl : UserControl
{
    // TODO: Expose a method for setting the DataContext of the hosted element!

    public WPFHostControl ()
    {
        InitializeComponent();

        ParentChanged += new EventHandler(WPFHostControl_ParentChanged);
    }

    void WPFHostControl_ParentChanged(object sender, EventArgs e)
    {
        if (Parent != null)
        {
            Size = Parent.ClientSize;
            Parent.ClientSizeChanged +=
                new EventHandler(Parent_ClientSizeChanged);
        }
    }

    void Parent_ClientSizeChanged(object sender, EventArgs e)
    {
        if (Parent != null)
        {
            Size = Parent.ClientSize;
        }
    }

    private MyWPFUserControl hostedControl;
    private System.Windows.Forms.Integration.ElementHost elementHost;

    /// <remarks>
    /// To make the Visual Studio designer work smoothly, you could
    /// split this function into a *.designer.cs file using a partial
    /// class definition.
    /// </remarks>
    private void InitializeComponent()
    {
        this.elementHost = new System.Windows.Forms.Integration.ElementHost();
        this.hostedControl = new MyWPFUserControl();
        this.SuspendLayout();
        // 
        // elementHost
        // 
        this.elementHost.Dock = System.Windows.Forms.DockStyle.Fill;
        this.elementHost.Location = new System.Drawing.Point(0, 0);
        this.elementHost.Name = "elementHost";
        this.elementHost.Size = new System.Drawing.Size(150, 150);
        this.elementHost.TabIndex = 0;
        this.elementHost.Child = this.hostedControl;
        // 
        // EnvironmentDashboard
        // 
        this.Controls.Add(this.elementHost);
        this.Name = "WPF Host View";
        this.ResumeLayout(false);

    }
}
//
///使用默认窗体视图定义范围节点,该视图将承载
///WPF控制。
/// 
公共类WPFScopeNode:ScopeNode
{
/// 
///实例化新的专用作用域节点。
/// 
公共WPFScopeNode()
:base()
{
this.DisplayName=“树视图中的名称”;
//TODO:创建任何子作用域节点,并将其添加到“this.Children”。
//将窗体视图附加到此承载WPF控件的节点。
var wpfFormView=新表单视图说明
{
DisplayName=“视图名称”,
ControlType=类型(WPFHostControl),
ViewType=typeof(WPFHostFormView)
};
this.viewsdescriptions.Add(wpfFormView);
}
}
/// 
///此类为托管WPF控件提供模型接口。
/// 
公共类WPFHostFormView:FormView
{
公共WPFHostFormView()
{
this.DescriptionBarText=“WPF主机视图”;
}
/// 
///定义表单视图的结构。
/// 
/// 
受保护的覆盖无效初始化(异步状态)
{
基础。初始化(状态);
//TODO:这可能是传递“This.Control”命令的好地方
//WPF将用于数据绑定的数据上下文
//控件。请注意,“this.control”是Windows窗体
//包含ElementHost的UserControl,ElementHost,
//托管感兴趣的WPF用户控件。
}
}
/// 
///定义承载特定WPF UserControl的Windows窗体控件。
///请注意中自动调整父曲面大小的逻辑
///MMC MDI接口。
///此外,“MyWPFUserControl”只是一个标准的WPF
///用户控制;对于MMC集成,不需要做任何特殊的工作。
/// 
公共部分类WPFHostControl:UserControl
{
//TODO:公开用于设置托管元素的DataContext的方法!
公共WPFHostControl()
{
初始化组件();
ParentChanged+=新事件处理程序(WPFHostControl_ParentChanged);
}
void WPFHostControl_ParentChanged(对象发送方,事件参数e)
{
如果(父项!=null)
{
Size=Parent.ClientSize;
Parent.ClientSizeChanged+=
新事件处理程序(父客户端大小更改);
}
}
void Parent\u ClientSizeChanged(对象发送方,事件参数e)
{
如果(父项!=null)
{
Size=Parent.ClientSize;
}
}
私有MyWPFUserControl宿主控件;
private System.Windows.Forms.Integration.ElementHost ElementHost;
/// 
///要使VisualStudio设计器顺利工作,您可以
///使用分部函数将此函数拆分为*.designer.cs文件
///类定义。
/// 
私有void InitializeComponent()
{
this.elementHost=new System.Windows.Forms.Integration.elementHost();
this.hostedControl=new MyWPFUserControl();
这个.SuspendLayout();
// 
//元素主机
// 
this.elementHost.Dock=System.Windows.Forms.DockStyle.Fill;
this.elementHost.Location=新系统.Drawing.Point(0,0);
this.elementHost.Name=“elementHost”;
this.elementHost.Size=新系统.图纸.尺寸(150150);
this.elementHost.TabIndex=0;
this.elementHost.Child=this.hostedControl;
// 
//环境仪表板
// 
this.Controls.Add(this.elementHost);
this.Name=“WPF主机视图”;
此选项为.resume布局(false);
}
}