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

时间:2016-09-28 11:06:24

标签: 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}" />

1 个答案:

答案 0 :(得分:0)

如果您的数据源是ObservableCollection,则可以使用自定义Count绑定到其IValueConverter属性,而不是将0转换为Visible和{{1}转到1并在Collapsed上使用它。不需要任何行为。