WPF TemplateData werden nicht angezeigt

  • WPF

    WPF TemplateData werden nicht angezeigt

    Servus!

    Hab am Wochenende ein Video auf YT (Windows für unterwegs - Windows Phone für .NET-Entwickler) gesehen, in dem in einer Silverlight App das Prinzip der Datenbindung anhand von Template Daten zu Design-Zeit gezeigt wird (ungefähr ab Minute 35).
    Ich wollte den Code mal auf ein Windows WPF Projekt anwenden, musste aber fest stellen, dass bei mir die Daten zur Design Zeit nicht angezeigt werden.

    Hier mal mein Code:

    C#-Quellcode

    1. using DataTemplateTest1.Model;
    2. using System;
    3. using System.Collections.ObjectModel;
    4. using System.Windows;
    5. namespace DataTemplateTest1
    6. {
    7. /// <summary>
    8. /// Interaktionslogik für MainWindow.xaml
    9. /// </summary>
    10. public partial class MainWindow : Window
    11. {
    12. private ViewModel viewModel;
    13. public MainWindow()
    14. {
    15. InitializeComponent();
    16. var p1 = new Post() { PostID = 1, UserName = "User1", EntryDate = new DateTime(2017, 02, 10, 12, 32, 25).ToString() };
    17. var p2 = new Post() { PostID = 2, UserName = "User2", EntryDate = new DateTime(2017, 02, 12, 10, 11, 12).ToString() };
    18. //this.lbTestDaten.ItemsSource = new ObservableCollection<Post>() { p1, p2 };
    19. viewModel = new ViewModel() { Posts = new ObservableCollection<Post>() { p1, p2 } };
    20. DataContext = viewModel;
    21. }
    22. }
    23. public class ViewModel
    24. {
    25. public ObservableCollection<Post> Posts { get; set; }
    26. }
    27. }

    XML-Quellcode

    1. <Window x:Class="DataTemplateTest1.MainWindow"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    6. xmlns:local="clr-namespace:DataTemplateTest1"
    7. mc:Ignorable="d"
    8. Title="MainWindow"
    9. Height="350" Width="525"
    10. d:DataContext="{d:DesignData Source=/SampleData/PostData.xaml}">
    11. <Grid>
    12. <ListBox
    13. x:Name="lbTestDaten"
    14. Background="Black"
    15. ItemsSource="{Binding Posts}">
    16. <ListBox.ItemTemplate>
    17. <DataTemplate>
    18. <StackPanel
    19. Orientation="Horizontal"
    20. VerticalAlignment="Center"
    21. HorizontalAlignment="Center"
    22. Height="35">
    23. <TextBlock
    24. x:Name="PostID"
    25. Text="{Binding PostID}"
    26. Height="35"
    27. Width="35"
    28. Margin="5"
    29. Foreground="White"/>
    30. <StackPanel
    31. Orientation="Vertical">
    32. <TextBlock
    33. x:Name="tbUserName"
    34. Text="{Binding UserName}"
    35. FontSize="15"
    36. Foreground="Blue"/>
    37. <TextBlock
    38. x:Name="tbEntryDate"
    39. Text="{Binding EntryDate}"
    40. FontSize="10"
    41. Foreground="Yellow"/>
    42. </StackPanel>
    43. </StackPanel>
    44. </DataTemplate>
    45. </ListBox.ItemTemplate>
    46. </ListBox>
    47. </Grid>
    48. </Window>

    XML-Quellcode

    1. <DataTemplateTest1:ViewModel
    2. xmlns:DataTemplateTest1="clr-namespace:DataTemplateTest1"
    3. xmlns:Model="clr-namespace:DataTemplateTest1.Model">
    4. <DataTemplateTest1:ViewModel.Posts>
    5. <Model:Post PostID="1" UserName="User1" EntryDate="10.02.2017" />
    6. <Model:Post PostID="2" UserName="User2" EntryDate="12.02.0217"/>
    7. </DataTemplateTest1:ViewModel.Posts>
    8. </DataTemplateTest1:ViewModel>


    Kann mir wer sagen, was ich da falsch mache?

    Edit: Alle Tabs des Projekts zugemacht und wieder geöffnet -> funzt wieder (TemplateDaten werden angezeigt)
    In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell