Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
De_Struktor
unregistriert
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MultiItems" x:Class="MultiItems.MainWindow" Title="MainWindow" Height="350" Width="200"> <Window.DataContext> <local:MainWindowModel/> </Window.DataContext> <Grid> <Grid.RowDefinitions> <RowDefinition Height="20"/> <RowDefinition/> </Grid.RowDefinitions> <Button Grid.Row="0" Command="{Binding AddCommand}" Content="New Mail"/> <ScrollViewer Grid.Row="1"> <ItemsControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding MailItems}"> <ItemsControl.ItemTemplate> <DataTemplate> <local:MailItemView DataContext="{Binding}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> </Grid> </Window> |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.Collections.ObjectModel; using System.Windows.Input; namespace MultiItems { internal class MainWindowModel { private readonly ICommand _addCommand; public MainWindowModel() { _addCommand = new CommandHandler(ExecuteAdd); } public ICommand AddCommand { get { return _addCommand; } } private readonly ObservableCollection<MailItemViewModel> _mailItems = new ObservableCollection<MailItemViewModel>(); public ObservableCollection<MailItemViewModel> MailItems { get { return _mailItems; } } private void ExecuteAdd() { MailItems.Add(new MailItemViewModel(OnDeleteMail) {Name = string.Empty, EMail = "foo@bar.de"}); } private void OnDeleteMail(object sender, EventArgs eventArgs) { var mail = sender as MailItemViewModel; if (mail == null) return; _mailItems.Remove(mail); } } } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<UserControl x:Class="MultiItems.MailItemView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid Margin="5"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Label Grid.Column="0" Grid.Row="0" Content="Name: "/> <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Name}" Margin="2"/> <Label Grid.Column="0" Grid.Row="1" Content="Mail: "/> <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding EMail}" Margin="2"/> <Button Height="20" Grid.ColumnSpan="2" Grid.Row="2" Margin="2" Content="Delete" Command="{Binding DeleteCommand}"/> </Grid> </UserControl> |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
using System; using System.Windows.Input; namespace MultiItems { class MailItemViewModel { private readonly EventHandler<EventArgs> _onDeleteRequest; private readonly ICommand _deleteCommand; public MailItemViewModel(EventHandler<EventArgs> onDeleteRequest) { _onDeleteRequest = onDeleteRequest; _deleteCommand = new CommandHandler(() => { if (_onDeleteRequest != null) _onDeleteRequest(this, new EventArgs()); }); } public string Name { get; set; } public string EMail { get; set; } public ICommand DeleteCommand { get { return _deleteCommand; } } } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System; using System.Windows.Input; namespace MultiItems { public class CommandHandler : ICommand { private readonly Action _action; private readonly bool _canExecute; public CommandHandler(Action action, bool canExecute = true) { _action = action; _canExecute = canExecute; } public bool CanExecute(object parameter) { return _canExecute; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { if(_action != null) _action(); } } } |
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »BlueCobold« (26.11.2013, 09:51)
C#-Quelltext |
|
1 2 3 4 5 6 |
protected void SetPropertyValue<T>(string propertyName, ref T backingField, T value) { if (Equals(backingField, value) return; backingField = value; OnPropertyChanged(propertyName); } |
C#-Quelltext |
|
1 2 3 4 5 |
public string Name { get { return _name; } set { SetPropertyValue("Name", ref _name, value); } } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Quellcode |
|
1 2 3 4 5 |
<ResourceDictionary> <DataTemplate DataType="{x:Type MyViewModelType}"> <!-- Mein View --> </DataTemplate> </ResourceDictionary> |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige