I am fairly new to programming. I have been learning C# for the last couple of months, and recently started with WPF.
Generally while writing code, I can put a breakpoint, and then I am able to hover the mouse over every variable to see what its current value is. I have found this very useful for debugging code. I can also follow along in the “Locals” window.
I am struggling to find a similar method while writing WPF apps. If I put a breakpoint, I can hover over each variable and see the initial value of it, but the Main Window doesn’t launch. But when I run the app, I don’t have the option to follow the variables in the code like this.
Is there a way that I can launch the application, and follow the variable values in my code, while messing around with the controls in the application?
Just to include a simple example, I have made a ComboBox with 3 options, and a textblock that shows the selected option:
Image of MainWindow
, with this as the code behind:
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
DataContext = this;
_allOptions = new ObservableCollection<string>();
_allOptions.Add("Option 1");
_allOptions.Add("Option 2");
_allOptions.Add("Option 3");
InitializeComponent();
}
private ObservableCollection<string> _allOptions;
private string _selectedOption;
public ObservableCollection<string> AllOptions
{
get { return _allOptions; }
set
{
_allOptions = value;
}
}
public string SelectedOption
{
get { return _selectedOption; }
set
{
_selectedOption = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
I want to be able to follow the value of _selectedOption
while the app is running.
How do I do that?
Thanks
I have tried looking around in Visual Studio for an option that shows me what I want, but haven’t found anything.
mmdn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2