Presence_Desktop/Presence.Desktop/Views/EditUserDialog.axaml.cs

57 lines
1.7 KiB
C#
Raw Normal View History

2024-12-23 11:26:41 +00:00
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Presence.Desktop.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Presence.Desktop
{
public partial class EditUserDialog : Window
{
private TextBox _nameTextBox;
private ComboBox _groupComboBox;
public EditUserDialog(Guid currentUserId, string currentName, int currentGroupId, List<GroupPresenter> groups)
{
_nameTextBox = new TextBox { Text = currentName };
_groupComboBox = new ComboBox
{
ItemsSource = groups,
SelectedItem = groups.FirstOrDefault(g => g.Id == currentGroupId),
ItemTemplate = new FuncDataTemplate<GroupPresenter>((group, _) =>
new TextBlock { Text = group.Name })
};
var confirmButton = new Button { Content = "OK" };
confirmButton.Click += (sender, args) =>
{
var newFio = _nameTextBox.Text;
var selectedGroup = (GroupPresenter)_groupComboBox.SelectedItem;
if (selectedGroup != null)
{
var newGroupId = selectedGroup.Id;
this.Close();
}
};
Content = new StackPanel
{
Children = { _nameTextBox, _groupComboBox, confirmButton }
};
}
public async Task<(string, GroupPresenter)> ShowDialog(Window parent)
{
await base.ShowDialog(parent);
var name = _nameTextBox.Text;
var groupId = (GroupPresenter)_groupComboBox.SelectedItem;
return (name, groupId);
}
}
}