#if UNITY_5_3_OR_NEWER #define NOESIS using Noesis; using UnityEngine; #else using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; #endif namespace Fury.UI.Windows { public partial class StartMPGameControl : UserControl { public StartMPGameControl() { this.Initialized += OnInitialized; InitializeComponent(); } #if NOESIS void InitializeComponent() => NoesisUnity.LoadComponent(this); #endif public TextBox PlayerNameTextBox; public TextBox IPTextBox; public TextBox PortTextBox; void OnInitialized(object sender, EventArgs args) { // this.DataContext is null PlayerNameTextBox = (TextBox)FindName("PlayerNameTextBox"); IPTextBox = (TextBox)FindName("IPTextBox"); PortTextBox = (TextBox)FindName("PortTextBox"); if (PlayerNameTextBox != null) { PlayerNameTextBox.TextChanged += OnPlayerInputTextBoxChanged; } if (IPTextBox != null) { IPTextBox.TextChanged += OnIPTextBoxChanged; } if (PortTextBox != null) { PortTextBox.TextChanged += OnPortTextBoxChanged; } } void OnPlayerInputTextBoxChanged(object sender, RoutedEventArgs e) { if (this.DataContext is StartMPGameViewModel viewModel) { //Debug.Log($"PlayerInput changed to: {kak}"); viewModel.PlayerName = PlayerNameTextBox.Text; } } void OnIPTextBoxChanged(object sender, RoutedEventArgs e) { if (this.DataContext is StartMPGameViewModel viewModel) { //Debug.Log($"IP changed to: {tak}"); viewModel.IPString = IPTextBox.Text; } } void OnPortTextBoxChanged(object sender, RoutedEventArgs e) { if (this.DataContext is StartMPGameViewModel viewModel) { //Debug.Log($"Port changed to: {pak}"); viewModel.PortString = PortTextBox.Text; } } /*public string PlayerInput { get { return (string)GetValue(PlayerInputProperty); } set { SetValue(PlayerInputProperty, value); } }*/ /*public static readonly DependencyProperty PlayerInputProperty = DependencyProperty.Register("PlayerInput", typeof(string), typeof(StartMPGameControl), new PropertyMetadata(string.Empty)); */ /*public static void OnPlayerInputChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var control = d as StartMPGameControl; if(control != null) { string newValue = e.NewValue as string; Debug.Log($"PlayerInput changed to: {newValue}"); } }*/ } }