C
C#7mo ago
Martixx

WPF Question MVVM

My Task is: Entry of simple address data for a person (name, surname, street, postcode, city) via an input mask. It should be possible to assign any number of telephone numbers (private, business, mobile, etc.). In the Screenshot u can see my Interface atm. I want to implement telephone numbers now. But idk, how I should start with it..
using Probeaufgabe_WPF.Models;
using Probeaufgabe_WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Probeaufgabe_WPF.Views
{
/// <summary>
/// Interaction logic for OverviewPerson.xaml
/// </summary>
public partial class OverviewPerson : Window, INotifyPropertyChanged
{
public OverviewPerson()
{
InitializeComponent();

this.DataContext = new MainViewModel();
}

public event PropertyChangedEventHandler? PropertyChanged;

private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
PersonList.Items.Filter = FilterPerson;
}

private bool FilterPerson(object obj)
{
var person = (Person)obj;

bool filter= person.Name.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) || person.Surname.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) ||
person.Plz.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) || person.Location.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase);

return filter;
}
}
}
using Probeaufgabe_WPF.Models;
using Probeaufgabe_WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Probeaufgabe_WPF.Views
{
/// <summary>
/// Interaction logic for OverviewPerson.xaml
/// </summary>
public partial class OverviewPerson : Window, INotifyPropertyChanged
{
public OverviewPerson()
{
InitializeComponent();

this.DataContext = new MainViewModel();
}

public event PropertyChangedEventHandler? PropertyChanged;

private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
PersonList.Items.Filter = FilterPerson;
}

private bool FilterPerson(object obj)
{
var person = (Person)obj;

bool filter= person.Name.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) || person.Surname.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) ||
person.Plz.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase) || person.Location.Contains(FilterTextBox.Text, StringComparison.OrdinalIgnoreCase);

return filter;
}
}
}
2 Replies
Martixx
MartixxOP7mo ago
I can't just extend the ListView to the right for each phone number, that would be unnecessarily complicated in my opinion And also the question would be, since I am supposed to add as many phone numbers as I want for one person, what is the best way to do this in terms of UI? -------- Sorry, I'm still pretty new to WPF
ACiDCA7
ACiDCA77mo ago
you could create a detailview for a person basicly show in you datagrid just basic information (you could concat all the phonenumbers there) and when you doubleclick or on another action open another view where all the other information is provided. you could also then move the update person logic into the new view and add person logic into a seperate view so you have clear distinction what the user can do on a particular view
Want results from more Discord servers?
Add your server