2015-10-07 96 views
0

以下是ListView的XAML代碼。定義ListView項目模板的邊框

<ListView VerticalAlignment="Stretch" 
      HorizontalAlignment="Stretch" 
      x:Name="listView1"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <Border HorizontalAlignment="Stretch" 
        BorderThickness="1" 
        BorderBrush="LightBlue"> 
       <StackPanel Orientation="Vertical"> 
        <Label BorderThickness="0,0,0,1" 
          BorderBrush="#BABABA" 
          HorizontalAlignment="Stretch">Keywords</Label> 
        <TextBlock Text="{Binding keywords}" 
           Foreground="#3399AA" 
           HorizontalAlignment="Stretch" /> 
        <Label BorderThickness="0,0,0,1" 
          BorderBrush="#BABABA">Content</Label> 
        <TextBlock MaxHeight="50" 
           Text="{Binding contentAsString}" 
           TextWrapping="Wrap" 
           Foreground="Black" 
           Height="auto" 
           Width="auto" /> 
       </StackPanel> 
      </Border> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

這裏是它的外觀

...

不管是什麼我已經試過我不能對整個ListView項創建一個邊界。我們怎麼做到這一點?

+2

你想[拉伸](http://stackoverflow.com/q/3715781/1997232)ListViewItem?順便說一句,位圖按鈕看起來很醜,你應該在wpf中使用矢量圖形(Pathes等)。 – Sinatr

+0

你想完整的ListView是在一個邊框或只是一個ListViewItem –

+0

@Sinatr我同意按鈕的事情。這只是一個暫時的事情。你的鏈接解決了我的問題。我不知道我可以用這種方式給列表視圖項目提供樣式。現在一切都很好。 – ozgur

回答

1

嘗試用彈力

<ListView> 
     <ListView.ItemContainerStyle> 
     <Style TargetType="ListViewItem"> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
     </Style> 
     </ListView.ItemContainerStyle> 
    </ListView> 

。 。 。

<Viewbox Stretch="Fill"/>