Issue of XAML Binding for DataTemplate inside one more DataTemplate?

I am working on Universal Windows Applications, in my current project I was displayed the calendar events like this below figure. enter image description here

when I was open my application for the first time then it ask login prompt AAD, then after login successfully only the single events will be displayed but multiple events was not displayed. And also when I was click on my logout button and then again click on my login button the same issue happened.

This is the image after user login successfully into application for the first time.

enter image description here

But when I was open my application for second time it was displayed all events like first image.

This is the code I wrote inside my XAML Page.

<Grid Margin="0,05,0,0"  Background="Transparent" Height="60">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="70"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Rectangle Fill="#2B88D8" Grid.RowSpan="6" Margin="0,0,20,0" Visibility="{Binding TimeLineVisibility}"/>
            <Line Stroke="#2B88D8" X1="1300" Y1="0"  Grid.ColumnSpan="2" Margin="43,0,0,0"
               Grid.Row="{Binding RowNum}" Grid.RowSpan="{Binding RowSpanNum}"
                  StrokeDashArray="3,2"
                  StrokeThickness="1"  VerticalAlignment="Center" Visibility="{Binding TimeLineVisibility}"/>
            <StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Top"
                   Grid.Row="{Binding DateRowNum}" Grid.RowSpan="{Binding DateRowSpanNum}">
                <TextBlock Text="{Binding Hour}"  FontWeight="Light" Margin="5,0,0,0"  FontSize="15" Foreground="{Binding FontColor}" />
                <TextBlock Text="{Binding des}" FontWeight="Light" Margin="0,0,0,0"  FontSize="15" Foreground="{Binding FontColor}" />
            </StackPanel>
            <Grid Grid.ColumnSpan="2" Grid.RowSpan="6">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Line Stroke="#C3C3C3" X1="1300" Y1="0"  Grid.ColumnSpan="2" Grid.Row="1" Margin="62,-3,0,0"
                                                    StrokeThickness="1" StrokeDashArray="3,5"  VerticalAlignment="Center"/>

                <GridView  ItemsSource="{Binding EventsBefore30}" Grid.Row="0"
                           Visibility="{Binding LessThan30DescVisibility}"
                           Margin="62 0 0 2"
                           HorizontalAlignment="Stretch" 
                          HorizontalContentAlignment="Stretch">
                    <GridView.ItemContainerStyle>
                        <Style TargetType="GridViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                            <Setter Property="Margin" Value="0,0,0,0"/>
                            <Setter Property="Padding" Value="0"/>
                            <Setter Property="Height" Value="30"/>
                            <Setter Property="FontFamily" Value="Arial"/>
                        </Style>
                    </GridView.ItemContainerStyle>
                    <GridView.ItemTemplate>
                        <DataTemplate>
                            <Border Margin="0 -3 0 2" Padding="5,0,10,10" BorderBrush="#A6D1F5" Background="#C1E9FE" BorderThickness="5 0 0 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Grid.Row="0" Text="{Binding Subject}"  HorizontalAlignment="Left"  VerticalAlignment="Center"  Grid.Column="1" FontWeight="Bold"  Margin="0,0,15,0"  FontSize="15" Foreground="Black" />
                                    <TextBlock Grid.Row="0" Text="{Binding Location}"  HorizontalAlignment="Left"  VerticalAlignment="Center"  Grid.Column="1"  Margin="0,0,0,0"  FontSize="12" Foreground="Black" />
                                </StackPanel>

                            </Border>
                        </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>
                <Border Grid.Row="0" Margin="62 -3 10 2" 
                        Visibility="{Binding IsSingleEventBefore30}" 
                        BorderBrush="#A6D1F5" Background="#C1E9FE" BorderThickness="5 0 0 0" 
                        HorizontalAlignment="Stretch">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Grid.Row="0" Text="{Binding LessThan30Desc}"  
                                   HorizontalAlignment="Left"  VerticalAlignment="Center"  
                                   Grid.Column="1" FontWeight="Bold"  Margin="0,0,15,0" 
                                   FontSize="15" Foreground="Black" />
                        <TextBlock Grid.Row="0" Text="{Binding LessThan30Loc}"  
                                   HorizontalAlignment="Left"  VerticalAlignment="Center"  
                                   Grid.Column="1" FontWeight="Bold"  Margin="0,0,0,0"  
                                   FontSize="12" Foreground="Black" />
                    </StackPanel>
                </Border>

                                   <Image  Grid.ColumnSpan="2" Grid.RowSpan="3" Height="1.4"  Stretch="Fill" 
                        VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="0,10,0,0"
                                Source="Assets/linebrown.png"></Image>
            </Grid>


        </Grid>


 <ListView x:Name="listview"  Grid.Column="0" 
                   Grid.Row="3"  Background="Transparent" 
                ItemTemplate="{StaticResource ListViewTemplateRequests}">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="FontFamily" Value="Arial"/>
                </Style>
            </ListView.ItemContainerStyle>



        </ListView>

This is the Class file for Binding Data to List View and Grid View.

     using System;
     using System.Collections.Generic;
     using System.Collections.ObjectModel;
     using System.ComponentModel;
     using System.Linq;
     using System.Text;
     using System.Threading.Tasks;
     using Windows.UI.Xaml;
     namespace O365UWP_Dashboard
    {
      public class Hours : INotifyPropertyChanged
     {
      private string _hour;

    public string des { get; set; }
    public string hour24 { get; set; }
    //public string minute { get; set; }

    public static ObservableCollection<Hours> GethoursRecord()
    {
        ObservableCollection<Hours> GethoursRecord = new ObservableCollection<Hours>
        {
                 new Hours {Hour="12" , des="a",hour24="0",_rowSpanNum=6 ,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6, TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
                   new Hours {Hour="1" , des="a",hour24="1",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="2" , des="a" ,hour24="2",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="3" , des="a" ,hour24="3",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="4" , des="a",hour24="4",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="5" , des="a" ,hour24="5",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
              new Hours {Hour="6" , des="a" ,hour24="6",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
               new Hours {Hour="7" , des="a",hour24="7",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="8" , des="a",hour24="8",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="9"  , des="a",hour24="9",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="10" , des="a",hour24="10",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="11" , des="a" ,hour24="11",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
               new Hours {Hour="12", des="p" ,hour24="12",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="1" , des="p",hour24="13",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="2" , des="p",hour24="14",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="3" , des="p",hour24="15",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="4"  , des="p",hour24="16",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="5" , des="p",hour24="17",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="6" , des="p" ,hour24="18",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
              new Hours {Hour="7" , des="p",hour24="19",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
               new Hours {Hour="8" , des="p",hour24="20",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="9" , des="p",hour24="21",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
             new Hours {Hour="10" , des="p",hour24="22",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},
            new Hours {Hour="11" , des="p",hour24="23",_rowSpanNum=6,_rowNum=0,_dateRowNum=0,_dateRowSpanNum=6,TimeLineVisibility=Visibility.Collapsed,GreaterThan30DescVisibility=Visibility.Collapsed,LessThan30DescVisibility=Visibility.Collapsed,FontColor="Black",IsSingleEventAfter30=Visibility.Collapsed,IsSingleEventBefore30=Visibility.Collapsed},


        };
        return GethoursRecord;
    }

    private string _desc;
    public string Desc
    {
        get { return _desc; }
        set
        {
            _desc = value;
            OnPropertyChanged("Desc");
        }
    }

    private string _greaterThan30Desc;
    public string GreaterThan30Desc
    {
        get { return _greaterThan30Desc; }
        set
        {
            _greaterThan30Desc = value;
            OnPropertyChanged("GreaterThan30Desc");
        }
    }
    private string _lessThan30Desc;
    public string LessThan30Desc
    {
        get { return _lessThan30Desc; }
        set
        {
            _lessThan30Desc = value;
            OnPropertyChanged("LessThan30Desc");
        }
    }

    private string _greaterThan30Loc;
    public string GreaterThan30Loc
    {
        get { return _greaterThan30Loc; }
        set
        {
            _greaterThan30Loc = value;
            OnPropertyChanged("GreaterThan30Loc");
        }
    }
    private string _lessThan30Loc;
    public string LessThan30Loc
    {
        get { return _lessThan30Loc; }
        set
        {
            _lessThan30Loc = value;
            OnPropertyChanged("LessThan30Loc");
        }
    }

    private Visibility _greaterThan30DescVisibility;
    public Visibility GreaterThan30DescVisibility
    {
        get { return _greaterThan30DescVisibility; }
        set
        {
            _greaterThan30DescVisibility = value;
            OnPropertyChanged("GreaterThan30DescVisibility");
        }
    }
    private Visibility _isSingleEventBefore30;
    public Visibility IsSingleEventBefore30
    {
        get { return _isSingleEventBefore30; }
        set
        {
            _isSingleEventBefore30 = value;
            OnPropertyChanged("IsSingleEventBefore30");
        }
    }

    private Visibility _isSingleEventAfter30;
    public Visibility IsSingleEventAfter30
    {
        get { return _isSingleEventAfter30; }
        set
        {
            _isSingleEventAfter30 = value;
            OnPropertyChanged("IsSingleEventAfter30");
        }
    }
    private Visibility _lessThan30DescVisibility;
    public Visibility LessThan30DescVisibility
    {
        get { return _lessThan30DescVisibility; }
        set
        {
            _lessThan30DescVisibility = value;
            OnPropertyChanged("LessThan30DescVisibility");
        }
    }

    private int _rowSpanNum;
    public int RowSpanNum
    {
        get
        {
            return _rowSpanNum;
        }

        set
        {
            _rowSpanNum = value;
            OnPropertyChanged("RowSpanNum");
        }
    }
    private int _rowNum;
    public int RowNum
    {
        get
        {
            return _rowNum;
        }

        set
        {
            _rowNum = value;
            OnPropertyChanged("RowNum");
        }
    }

    private int _dateRowSpanNum;
    public int DateRowSpanNum
    {
        get
        {
            return _dateRowSpanNum;
        }

        set
        {
            _dateRowSpanNum = value;
            OnPropertyChanged("DateRowSpanNum");
        }
    }
    private int _dateRowNum;
    public int DateRowNum
    {
        get
        {
            return _dateRowNum;
        }

        set
        {
            _dateRowNum = value;
            OnPropertyChanged("DateRowNum");
        }
    }
    public Visibility TimeLineVisibility
    {
        get
        {
            return _timeLineVisibility;
        }

        set
        {
            _timeLineVisibility = value;
            OnPropertyChanged("TimeLineVisibility");
        }
    }

    public string Hour
    {
        get
        {
            return _hour;
        }

        set
        {
            _hour = value;
            OnPropertyChanged("Hour");
        }
    }

    public string FontColor
    {
        get
        {
            return _fontColor;
        }

        set
        {
            _fontColor = value;
            OnPropertyChanged("FontColor");
        }
    }

    private List<Events> _eventsBefore30;
    //public List<Events> EventsBefore30 { get; set; }
    private List<Events> _eventsAfter30;

    public List<Events> EventsBefore30
    {
        get
        {
            return _eventsBefore30;
        }

        set
        {
            _eventsBefore30 = value;
            OnPropertyChanged("EventsBefore30");
        }
    }

    public List<Events> EventsAfter30
    {
        get
        {
            return _eventsAfter30;
        }

        set
        {
            _eventsAfter30 = value;
            OnPropertyChanged("EventsAfter30");
        }
    }

    private Visibility _timeLineVisibility;
    private string _fontColor;
    private void OnPropertyChanged(string v)
    {

        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(v));

    }
    public event PropertyChangedEventHandler PropertyChanged;
}

}

there was no issues in the backend code for my logic.

-Pradeep


ANSWERS:


I changed these two lines of code to observable collection then it's working fine.

 private List<Events> _eventsBefore30;
//public List<Events> EventsBefore30 { get; set; }
private List<Events> _eventsAfter30

After I changed above lines to observable collection then it's looks like below lines.

           private ObservableCollection<Events> _eventsBefore30=new ObservableCollection<Events>();

    //public List<Events> EventsBefore30 { get; set; }
    private ObservableCollection<Events> _eventsAfter30 = new ObservableCollection<Events>();


 MORE:


 ? Xaml style isn't applied to all buttons
 ? UWP Why does a style not apply to TargetTypes in DataTemplate?
 ? UWP Why does a style not apply to TargetTypes in DataTemplate?
 ? UWP Why does a style not apply to TargetTypes in DataTemplate?
 ? ThemeResource in Style isn't used when I build my UWP app
 ? uwp define eventriggerbehavior inside style
 ? How to apply same style to all the textbox's at visual state setters in a single setter using uwp
 ? Creating a DataTemplate in UWP from code
 ? HorizontalAlignment Stretch does not work as expected
 ? HorizontalAlignment Stretch does not work as expected