2015-04-15 63 views
0

如何編輯代碼中某些列表視圖項目的字體重量?例如,我添加了兩行項目,並且想要加粗第一行。這裏是我的.xaml代碼:如何編輯所選列表視圖項目的字體屬性

<ListView x:Name="AInfoLv" FontFamily="Tahoma" FontSize="11" Background="{x:Null}"> 
    <ListView.View> 
    <GridView> 
     <GridViewColumn x:Name="LabelColumn" Header="Label" Width="80" DisplayMemberBinding="{Binding Label}" /> 
     <GridViewColumn x:Name="ValueColumn" Header="Value" Width="80" DisplayMemberBinding="{Binding Value}" /> 
    </GridView> 
    </ListView.View> 
    <ListView.ItemContainerStyle> 
    <Style TargetType="ListViewItem"> 
     <Setter Property="FontSize" Value="11"/> <Setter Property="FontFamily" Value="Tahoma"/> <Setter Property="FontWeight" Value="Normal"/> 
    </Style> 
    </ListView.ItemContainerStyle> 
</ListView> 

而且添加我的項目,如:

public Info() 
{ 
    InitializeComponent(); 
    this.AInfoLv.Items.Add(new { Label = "A", Value = "123" }); 
    this.AInfoLv.Items.Add(new { Label = "B", Value = "456" }); 

} 

回答

0

所有您需要提供的造型你的ListView和csutomise所選項目的視圖。這裏是一個例子。你可以根據你的需要進一步定製事件。

<ListView.Resources> 
     <ControlTemplate x:Key="SelectedTemplate" TargetType="ListViewItem"> 
      <Border SnapsToDevicePixels="true" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        Background="{TemplateBinding Background}" 
        CornerRadius="5" x:Name="border"> 
       <ContentControl 
        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
        Margin="2,2,2,2" 
        VerticalAlignment="Stretch" 
        Content="{TemplateBinding Content}" /> 
      </Border> 
     </ControlTemplate> 
     <Style TargetType="ListViewItem"> 
      <Style.Triggers> 
       <MultiTrigger> 
        <MultiTrigger.Conditions> 
         <Condition Property="IsSelected" Value="true" /> 
         <Condition Property="Selector.IsSelectionActive" Value="true" /> 
        </MultiTrigger.Conditions> 
        <Setter Property="Background" Value="Pink" /> 
        <Setter Property="Template" Value="{StaticResource SelectedTemplate}" /> 
       </MultiTrigger> 
      </Style.Triggers> 
     </Style> 
    </ListView.Resources> 
    <ListView.View> 
<GridView> 
    <GridViewColumn x:Name="LabelColumn" Header="Label" Width="80" DisplayMemberBinding="{Binding Label}" /> 
    <GridViewColumn x:Name="ValueColumn" Header="Value" Width="80" DisplayMemberBinding="{Binding Value}" /> 
</GridView> 

相關問題