I’m new to WPF and from the get-go, I’m trying out MVVM.
I’m trying to create an app which is based on the option that is chosen by the user in the combo box. I want all the contents of other controls in the app cleared when the new option is chosen. So far, the content do get cleared off but new content is no longer being written in. It just stays as zero/null. I feel that there is something wrong in my approach.
Here’s the combo box defined in MainWindow.xaml
<ComboBox
x:Name="section"
Margin="0,2,5,2"
Padding="2,2,0,0"
SelectedItem="{Binding SelectedSection}">
<!-- Some combo items go here -->
</ComboBox>
Here’s the property it is binded to:
public ComboBoxItem SelectedSection
{
get { return _selectedSectionType; }
set
{
ClearContentUponSelection();
_selectedSectionType = value;
// some other logic here based on the selected section type
}
}
ClearContentUponSelection()
method simply clears the other controls (like textbox, labels…) of the data entered inside by the user.
Here’s an example of a property being cleared off and staying zero despite new user input
public double Breadth
{
get => _breadth;
set
{
_breadth = value; OnPropertyChanged(nameof(Breadth));
}
}
Could someone help me with this? Thanks!
Secret Ambush is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7