代码之家  ›  专栏  ›  技术社区  ›  Arjun Balip

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

  •  0
  • Arjun Balip  · 技术社区  · 8 年前

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

    <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 回复  |  直到 8 年前
        1
  •  0
  •   Igor Kulman    8 年前

    如果您的数据源是 ObservableCollection 你可以绑定到它 Count 自定义属性 IValueConverter 0 Visible 1 Collapsed 并将其用于 TextBlock 。无需任何行为。