我正在开发通用Windows应用程序,在我当前的项目中,我显示了如下图所示的日历事件。
当我第一次打开我的应用程序时,它会询问登录提示AAD,然后在登录成功后,只显示单个事件,但不显示多个事件。而且,当我点击我的注销按钮,然后再次点击我的登录按钮时,同样的问题就发生了。
这是用户首次成功登录应用程序后的图像。
但是当我第二次打开我的应用程序时,它显示了所有事件,如第一张图片。
这是我在XAML页面中编写的代码。
SELECT ID,
MAX(CASE WHEN alias = 'test1' THEN value ELSE NULL END) AS test1,
MAX(CASE WHEN alias = 'test2' THEN value ELSE NULL END) AS test2,
MAX(CASE WHEN alias = 'test3' THEN value ELSE NULL END) AS test3
FROM yourTable
GROUP BY ID
这是将数据绑定到列表视图和网格视图的类文件。
<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>
}
我的逻辑后端代码没有问题。
-Pradeep
答案 0 :(得分:0)
我将这两行代码更改为可观察的集合,然后它正常工作。
private List<Events> _eventsBefore30;
//public List<Events> EventsBefore30 { get; set; }
private List<Events> _eventsAfter30
在我将上面的行更改为可观察的集合后,它看起来就像下面的行。
private ObservableCollection<Events> _eventsBefore30=new ObservableCollection<Events>();
//public List<Events> EventsBefore30 { get; set; }
private ObservableCollection<Events> _eventsAfter30 = new ObservableCollection<Events>();