当列表框为空时显示默认消息 (Windows Phone 8.1)

Show default message when listbox is empty (Windows Phone 8.1)

我想在列表框为空时显示默认消息,为此我使用了以下代码,但此代码不起作用:

<HubSection x:Name="PivotFromAccount" Style="{StaticResource HubSectionStyle2}"  >
                <DataTemplate>

                    <Border Style="{StaticResource brdhubsectionstyle}">
                        <Grid Grid.Row="1" Style="{StaticResource GridMainStyleHubSession}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border Style="{StaticResource brdheaderstyle}">
                                <TextBlock Text="From Account" Style="{StaticResource lblheaderstyle}"  />
                            </Border>

                            <ListBox   x:Name="lstAccountDetailsfrom" Grid.Row="1" ItemsSource="{Binding }" 
                                   Style="{StaticResource LstBoxStyleBranches}"  
                                   Tapped="lstAccountDetailsfrom_Tapped" 
                                   ItemContainerStyle="{StaticResource lstAccountliststyle}"
                                 ItemTemplate="{StaticResource lstAccountlistDataTemplate}" >
                            </ListBox>

                            <TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" x:Name="txtmessage" Grid.Row="1" Foreground="Black"  />



                          <i:Interaction.Behaviors>
                                <ic:DataTriggerBehavior Binding="{Binding ElementName=lstAccountDetailsfrom, Path=Items.Count,Converter={StaticResource DataTriggerBehavior},Mode=TwoWay}" Value="0" ComparisonCondition="GreaterThan">
                                    <ic:ChangePropertyAction TargetObject="{Binding ElementName=txtmessage}" PropertyName="Visibility" Value="Collapsed"/>
                                </ic:DataTriggerBehavior>
                            </i:Interaction.Behaviors>


                        </Grid>
                    </Border>
                </DataTemplate>
            </HubSection>

我也像下面这样尝试使用 Ivalue 转换器,但它也没有太大帮助。它总是向 ValueConverter

发送 0 个计数
<TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="List is empty" x:Name="txtmessage" Grid.Row="1" Foreground="Black" Visibility="{Binding ElementName=lstAccountDetailsfrom,Converter={StaticResource DataTriggerBehavior},Mode=TwoWay}" />

如果您的数据源是 ObservableCollection,您可以使用自定义 IValueConverter 绑定到它的 Count 属性,而不是将 0 转换为 Visible1Collapsed 并在 TextBlock 上使用它。无需行为。