Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

WPF Dialog in WindowsForms-Anwendung aufrufen

Empfohlene Antworten

Veröffentlicht

Hallo FI Kolleginnen & Kollegen!

Ich machs kurz: :)

Und zwar habe ich einen Dialog in einem WPF-Projekt erstellt. (Window1.xaml)

In der gleichen Solution hab ich ein WindowsForms-Projekt.

Dieses WindowsForms-Projekt soll den WPF-Dialog aufrufen.

Alles in C#.

Wie kann man so etwas machen?

Bin für jeden Tipp dankbar! :)

Gruß

WPF-Objekte sind auch nur Klassen (XAML = Content - XAML.cs = Code-Behind)

Folglich erzeugst du einfach ein Objekt des Dialogs (ich nehm mal an, dass es ein Window ist) mit Hilfe von new.

Sobald du dann die Instanz hast, rufst du einfach Show bzw. ShowDialog auf.

Je nachdem, ob es bei einem Buttonklick oder sonst einem Ereignis/... geschehen soll.

Hallo TDM.

Erst einmal danke das du dir Zeit genommen hast mir zu antworten. :)

Leider bringt mich das nicht weiter.

Kann es sein das mir eine Reference, ein Using oder etwas ähnliches fehlt?

Ich habe mal einen Screenshot meines "Solution Explorer" gemacht. (Ist als Anhang am Post)

Hier noch der Code den ich verwende. (Aus einer Demo-Applikation)

Der WPF-Dialog:


<Window x:Class="WpfApplication.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Window1" Height="300" Width="300">

    <Grid>

        <Button HorizontalAlignment="Right" Margin="0,121,2,118" Name="button1" Width="75">Button</Button>

        <TextBox Margin="12,121,83,118" Name="textBox1" />

        <Label Height="28" Margin="12,93,0,0" Name="label1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120">Enter your text here.</Label>

    </Grid>

</Window>

Hier der Code aus der Form meines "Windows Forms" Projektes:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;


namespace MyWPFApplication

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();            

        }


        private void OpenDialogBtn_Click( object sender, EventArgs e )

        {

            // open the wpf dialog here            

        }

    }

}

Gruß

post-44944-14430448411788_thumb.jpg

In der gleichen Solution hab ich ein WindowsForms-Projekt.

Da liegt das Problem.

Ich nahm an, dass Windows-Forms und WPF im gleichen Projekt sind.

Sieht aber bei dem Screenshot nicht so aus. Folglich brauchst du in "WinFormsApplication" noch einen Verweiß (Reference) auf WPFApplication. Damit die Klassen des WPF-Projekts verwendbar werden.

Nach dem einfügen der Reference zu meinem WPF-Projekt und dem einfügen ein paar weiterer References funktionierts.

Vielen Dank !!! :uli

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.