Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Accessing Text Box Values from Window to another class

$
0
0

Mainview model

public class MainViewModel : INotifyPropertyChanged
	{
		public MainViewModel()
		{
			// Insert code required on object creation below this point.
		}
		private string name;
		public string Name
		{ 
			get
			{
				return name;
			}
			set
			{
				name = value;
				NotifyPropertyChanged("Name");
			}
		}
		#region INotifyPropertyChanged
		public event PropertyChangedEventHandler PropertyChanged;

		public void NotifyPropertyChanged(String info)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(info));
			}
		}
		#endregion

	}

Window xaml

<Window.Resources><local:MainViewModel x:Key="ViewModel" /></Window.Resources><Grid x:Name="LayoutRoot" Background="White"><TextBox Height="44" Margin="200,104,200,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="18.667" Text="{Binding Source={StaticResource ViewModel}, Path=Name, UpdateSourceTrigger=PropertyChanged}"/><TextBlock Height="44" Margin="200,193,200,0" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="18.667" Text="{Binding Source={StaticResource ViewModel}, Path=Name, UpdateSourceTrigger=PropertyChanged}" Background="Black" Foreground="White"/><TextBlock Height="44" Margin="97,104,0,0" TextWrapping="Wrap" Text="Name :" VerticalAlignment="Top" FontSize="21.333" HorizontalAlignment="Left" Width="103"/><Button Content="DIALOG" Height="42" Margin="200,32,200,0" VerticalAlignment="Top" Click="ShowDialog"/></Grid>

window.cs

public partial class MainWindow : Window
	{
		public MainWindow()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}
        private void ShowDialog(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here
            Dialog dlg = new Dialog();
            dlg.Owner = this;
            dlg.ShowDialog();
        }
	}

window dialog xaml

<Window.Resources><local:MainViewModel x:Key="ViewModel" /></Window.Resources><Grid x:Name="LayoutRoot" Background="Red"><TextBox Height="54" Margin="231,185,40,0" TextWrapping="Wrap" Text="{Binding Source={StaticResource ViewModel}, Path=Name}" VerticalAlignment="Top" FontSize="21.333"/><TextBlock HorizontalAlignment="Left" Height="54" Margin="72,185,0,0" TextWrapping="Wrap" Text="Name :" VerticalAlignment="Top" Width="159" FontSize="24"/></Grid>

I created window with textbox and button for window dialog.

I want to get value from textbox in window to window dialog texbox

this my screenshoot :

How can i do this?please guide me.... 

Thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>