DBC WPF
WPF https://www.wpftutorial.net/WPFIntroduction.html
První WPF aplikace https://www.wpftutorial.net/HelloWPF.html
XAML - úvod https://wpf-tutorial.com/xaml/basic-xaml/ https://wpf-tutorial.com/xaml/events-in-xaml/ Ukázat jen událost (ne handler) Událost klik na tlačítko Vytvořit z panelu/ručně https://wpf-tutorial.com/wpf-application/the-window/ Jet dále Vynechat Command-line, Handling Exceptions
XAML https://wpf-tutorial.com/data-binding/using-the-datacontext/ Opakování Ukázat ElementName, připomenout UpdateSourceTrigger Nastavit DataContext v XAML Name="win" DataContext="{Binding ., ElementName=win}“ Ukázat RelativeSource Self
Responding to changes https://wpf-tutorial.com/data-binding/responding-to-changes/ Ukázat, jak to nechodí Změnit na ObservableCollection PropertyChanged, po novu protected void OnPropertyChanged(string name) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } public void OnPropertyChanged<T>(Expression<Func<T>> propertyExpression) this.OnPropertyChanged(propertyExpression.Name);
Počítané pole public string FullName => "Pepa " + Name;
Oprava – user s bindingem Udělat getter na seznam Userů private ObservableCollection<User> users; public ObservableCollection<User> Users { get if (users==null) users = new ObservableCollection<User>(); users.Add(new User() { Name = "John Doe" }); users.Add(new User() { Name = "Jane Doe" }); } return users;
Také v XAML <Window x:Class="PrvniWPF.ChangeNotificationSample" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="ChangeNotificationSample" Height="150" Width="300" DataContext="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}"> <ListBox Name="lbUsers" DisplayMemberPath="Name" ItemsSource="{Binding Users}"></ListBox> Ukázat Immediate Windows – např. chyba Binding Usersss
Problém – různé DataContexty! Nejprve špatně nový text v datacontextu okna ListBox public string MyText => "AHOJ"; <ListBox Name="lbUsers" ItemsSource="{Binding Users}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock FontWeight="ExtraBlack" Foreground="YellowGreen" Text="{Binding MyText}"/> <TextBlock Text="{Binding Name}"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Předchozí nefunguje - oprava <TextBlock FontWeight="ExtraBlack" Foreground="YellowGreen" Text="{Binding MyText}" DataContext="{Binding ElementName=window, Mode=OneWay}"/> Nebo <TextBlock FontWeight="ExtraBlack" Foreground="YellowGreen" Text="{Binding DataContext.MyText, ElementName=window}"/>
Resources https://wpf-tutorial.com/wpf-application/resources/ Jen ukázat Static vs. Dynamic Namaspaces
Styly Vyzkoušet: https://wpf-tutorial.com/styles/introduction/ Napsat si ručně.
Konvertory https://wpf-tutorial.com/data-binding/value-conversion-with-ivalueconverter/
Commands??