Przesyłanie informacji miedzy oknami

0

Witam mam pewien problem. Ponieważ stworzyłem projekt w wpf i chciałem przesłać informacje z MainWindow do Focus (UserControl) i kiedy ustawiłem tekst w MainWindow z klasy to po przesłaniu nie wyświetlał się i przychodzę do was z pytaniem w czym jest blad ? Poniżej wklejam fragment kodu

MainWindow

using ModKit_1._1.Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Przesylanie_miedzy_oknami
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            nFile nf = new nFile();
            nf.text = "przykladowy tekst";
        }
    }
}

Tutaj Focus czyli UserControl

using ModKit_1._1.Class;
using ScintillaNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Przesylanie_miedzy_oknami.View
{
    /// <summary>
    /// Interaction logic for Focus.xaml
    /// </summary>
    public partial class Focus : UserControl
    {
        public Focus()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            nFile nf = new nFile();
            textbox.Text = nf.text; 
        }
    }
}

A tutaj Klasa z której próbuje przesyłać/zmieniać informacje

using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Przesylanie_miedzy_oknami.Class
{
    class nFile
    {
        public string text;
    }

2

Nie działa Ci bo tworzysz drugi obiekt nFile. Albo przekazuj pierwotny obiekt przez konstruktor twojego userControl, albo uczyń statycznym pole text w klasie nField.

1 użytkowników online, w tym zalogowanych: 0, gości: 1