2009-10-02 84 views

回答

8

您可以使用ListView的HasItems依賴項屬性。使用觸發器時,如果屬性爲false,則可以更改ControlTemplate。這裏舉例:

<ListView ItemsSource="{Binding Items}"> 
    <ListView.Style> 
    <Style TargetType="{x:Type ListView}"> 
     <Style.Triggers> 
     <Trigger Property="HasItems" Value="False"> 
      <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListView}"> 
       <Border SnapsToDevicePixels="true" 
         Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}"> 
        <TextBlock Text="No items" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center"/> 
       </Border> 
       </ControlTemplate> 
      </Setter.Value> 
      </Setter> 
     </Trigger> 
     </Style.Triggers> 
    </Style> 
    </ListView.Style> 
</ListView> 
相關問題