• WPF-GridView设置列宽按比例分配


    1. 将ListView包裹在一个父Grid中
    2. 写一个与ListView平行的Grid,设置该Grid的列数与ListView中GridView的列数相同,将该Grid各列设置列宽按比例分配
    3. 将ListView中GridView的各列的Width绑定上述Grid的ActualWidth
    4. 这样,通过设置上述Grid各列的比例,就对应设置了ListView中GridView的各列的比例
     1 <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
     2     <Grid>
     3         <Grid.ColumnDefinitions>
     4             <ColumnDefinition Width="3*" />
     5             <ColumnDefinition Width="2*" />
     6             <ColumnDefinition Width="8*"/>
     7             <ColumnDefinition Width="5*"/>
     8             <ColumnDefinition Width="5*"/>
     9         </Grid.ColumnDefinitions>
    10         <Grid Grid.Column="0" x:Name="HumidifyEventLogCol0"/>
    11         <Grid Grid.Column="1" x:Name="HumidifyEventLogCol1"/>
    12         <Grid Grid.Column="2" x:Name="HumidifyEventLogCol2"/>
    13         <Grid Grid.Column="3" x:Name="HumidifyEventLogCol3"/>
    14         <Grid Grid.Column="3" x:Name="HumidifyEventLogCol4"/>
    15     </Grid>
    16 
    17     <ListView Name="HumidifyEventLog" Style="{StaticResource ListViewStyle}" ItemContainerStyle="{StaticResource ResourceKey=ListViewItemStyle}">
    18         <ListView.View>
    19             <GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
    20                 <GridViewColumn Header="设备" Width="{Binding ElementName=HumidifyEventLogCol0,Path=ActualWidth}" DisplayMemberBinding="{Binding Path=Source, Converter={StaticResource ChamberNameEnToCn}}"/>
    21                 <GridViewColumn Header="故障ID" Width="{Binding ElementName=HumidifyEventLogCol1,Path=ActualWidth}" DisplayMemberBinding="{Binding Path=Code}"/>
    22                 <GridViewColumn Header="故障描述" Width="{Binding ElementName=HumidifyEventLogCol2,Path=ActualWidth}" DisplayMemberBinding="{Binding Path=Remark}"/>
    23                 <GridViewColumn Header="故障开始时间" Width="{Binding ElementName=HumidifyEventLogCol3,Path=ActualWidth}" DisplayMemberBinding="{Binding Path=StartTime}"/>
    24                 <GridViewColumn Header="故障结束时间" Width="{Binding ElementName=HumidifyEventLogCol4,Path=ActualWidth}" DisplayMemberBinding="{Binding Path=EndTime}"/>
    25             </GridView>
    26         </ListView.View>
    27     </ListView>
    28 </Grid>

    参考:WPF GridView的宽度设置为按比例分配

  • 相关阅读:
    NSSM 将jar 安装成windows服务
    Spark Streaming
    记录一次oracle的坑 ORA08103
    POJ 3669 Meteor Shower
    LeetCode题目1~3
    POJ 3723 Conscription 并查集 + Kruskal
    LeetCode题目4:Sort List
    C++实现的快速排序
    C++实现的一段希尔排序代码
    2014大众点评Hackathon参赛感想
  • 原文地址:https://www.cnblogs.com/zwh1993/p/12795349.html
Copyright © 2020-2023  润新知