简体   繁体   中英

Show a Powerpoint Presentation in a Frame in WPF

What I try to achieve is to show a PowerPoint Presentation directly without opening Powerpoint beforhand in a WPF Window. Right now I'm using this code to start the Presentation:

    Process proc = new Process();
    proc.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE";
    proc.StartInfo.Arguments = " /s " + source.ToString();
    proc.Start();

with the variable source being the path to the desired file. This Code opens the PowerPoint Presentation in Fullscreen, which would be fine, but my Application is running on a Touch Device with no Keyboard or Mouse connected. So I would like to be able to put a overlay above the presentation itself with a "Close"-Button for example.

I already found this topic Hosting external app in WPF window , but I'm having a hard time understanding what's actually going on there.

I hope someone can help me.

Thanks in advance.

I managed to do it in a way I'm comfortable with. Here is the Code:

XAML:

<Window x:Name="window" x:Class="Project.PowerPointViewer"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Project"
        mc:Ignorable="d"
        Title="PowerPointViewer" Background="Transparent" Topmost="True" AllowsTransparency="True" ResizeMode="NoResize" WindowStyle="None" WindowState="Maximized">  

The important part being: Background, Topmost and AllowTransparency

Code Behind:

public partial class PowerPointViewer : Window
{
    Process proc = new Process();
    Window main;
    public PowerPointViewer(Window main)
    {
        InitializeComponent();
        this.main = main;
    }

    public void open(string source)
    {
        proc.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE";
        proc.StartInfo.Arguments = " /s " + source;
        proc.Start();
        Show();
    }

    private void bt_close_Click(object sender, RoutedEventArgs e)
    {
        if (!proc.HasExited)
            proc.Kill();
        Close();
        main.Focus();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM