Binden Sie die benutzerdefinierte Benutzersteuerung mit Kombinationsfeldern/Textfeldern über die Eigenschaft an ein WörtC#

Ein Treffpunkt für C#-Programmierer
Guest
 Binden Sie die benutzerdefinierte Benutzersteuerung mit Kombinationsfeldern/Textfeldern über die Eigenschaft an ein Wört

Post by Guest »

Hier ist ein Repo mit MWP: https://github.com/esqadron/avalonia-combo-boxes-dict. Das Hauptproblem liegt in den Ansichten/Specialcomboboxes.axaml.cs. Ekeys, string> . Jeder DICT -Eintrag entspricht dem Combobox/Textbox -Paar, das dynamisch mit einer Schaltfläche hinzugefügt wird. Wege, was bedeutet, dass es auf dem Bildschirm aktualisiert wird, wenn ich den textbox gebundenen Eigenschaften einen Wert hinzufüge, und wenn ich die gebundene Eigenschaft aktualisiere?
SpecialComBoboxes Klasse: < /p>
public partial class SpecialComboBoxes : UserControl
{
public SpecialComboBoxes()
{
InitializeComponent();

// TODO: - Bind Container/ContainerProperty to the children of SpecialComboBxesStackPanel so that the values can be set and read from Bound observable properties

}

public static readonly StyledProperty ContainerProperty = AvaloniaProperty.Register(
nameof(Container),
defaultValue: new KeyValues(),
defaultBindingMode: BindingMode.TwoWay);

public KeyValues Container
{
get => GetValue(ContainerProperty);
set => SetValue(ContainerProperty, value);
}

public void AddNewComboBox(object sender, RoutedEventArgs e)
{
StackPanel stackPanel = new StackPanel();

(ComboBox KeyComboBox, TextBox ValueTextBox) = createLine();

stackPanel.Children.Add(KeyComboBox);
stackPanel.Children.Add(ValueTextBox);
stackPanel.Orientation = Avalonia.Layout.Orientation.Horizontal;

SpecialComboBxesStackPanel.Children.Add(stackPanel);
}

private (ComboBox, TextBox) createLine()
{
ComboBox keyComboBox = new ComboBox();
keyComboBox.ItemsSource = Enum.GetValues(typeof(EKeys)).Cast();

keyComboBox.SelectionChanged += (sender, e) =>
{
// TODO - something here?
};

TextBox valueTextBox = new TextBox();

valueTextBox.TextChanged += (sender, e) =>
{
// TODO - something here?
};

return (keyComboBox, valueTextBox);
}

}
< /code>



< /code>
Expected usage from other UserControls/ViewModels:
public partial class MainViewModel : ViewModelBase
{
[ObservableProperty]
private KeyValues _boundKeyValues = new KeyValues();

public void GetValues()
{
foreach (var item in BoundKeyValues)
{
Console.WriteLine($"{item.Key} - {item.Value}");
}
}

public void FillValues()
{
BoundKeyValues = new KeyValues()
{
{ EKeys.Value1, "Value 1" },
{ EKeys.Value2, "Value 2" },
{ EKeys.Value3, "Value 3" },
{ EKeys.Value4, "Value 4" }
};
}
}
< /code>







< /code>
I tried multiple solutions from the web but none of them worked properly.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post