UserControlA.xaml
UserControlB.xaml
UserControlB.xaml.cs
public partial class UserControlB : UserControl
{
public static string infoB;
public UserControlB()
{
InitializeComponent();
}
private void Btn_Click(object sender, RoutedEventArgs e)
{
infoB = UBTxt.Text.ToString();
}
}
MianWindow.xaml
ViewModel.cs
public class ViewModel : INotifyPropertyChanged, ICommand
{
public string info;
public string Info
{
get
{
return info;
}
set
{
info = value;
OnPropertyChanged("Info");
}
}
public void Execute(object parameter)
{
Info = UserControlB.infoB;
}
public bool CanExecute(object parameter)
{
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler CanExecuteChanged;
private void OnPropertyChanged([CallerMemberName] string propName = "")
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}