WPF - GridView.GridViewColumn two rows in a row?

Hello, is it possible to have ListView -> ListView.View -> GridView -> GridViewColumn with "two rows" for each row.
eg.
            COLUMN 1 | COLUMN 2
ROW 1 blah data blah
ROW 2 | more

I tried unsuccessfully to use the cell template, but the element inside the template does not change when its containing column is manually changed.

code:

        <ListView Height="238" DockPanel.Dock="Top" ItemsSource="{Binding Blah}" 
              SelectedItem="{Binding Path=Selectedblah, UpdateSourceTrigger=PropertyChanged}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="No." DisplayMemberBinding="{Binding Path=Id}" Width="25" />
                <GridViewColumn Header="Job Type" DisplayMemberBinding="{Binding Path=Something}" Width="165" />
                <GridViewColumn Header="Assigned To" DisplayMemberBinding="{Binding Path=SomethingElse}" Width="90" />
                <GridViewColumn Header="Created" DisplayMemberBinding="{Binding Path=DateCreated, Converter={StaticResource dateTimeFormat}, ConverterParameter='dd/MM/yy HH:mm'}" Width="65" />
                <GridViewColumn>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="/Streetcar.UI.Modules.FleetTracker;component/Resources/Images/tick.png" Visibility="{Binding IsCompleted, Converter={StaticResource boolToVis}}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

Any ideas?

EDIT: this is using MVVM, so there is no code behind the limited ViewModel

+3
source share
5 answers

, . CellTemplate TextBlock TextWrapping, Wrap?

:

<ListView x:Name="MyListView">
   <ListView.View>
      <GridView>
         <GridViewColumn Header="Hello"
                         Width="50">
            <GridViewColumn.CellTemplate>
               <DataTemplate>
                  <TextBlock Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce non nibh quis odio aliquet venenatis."
                             TextWrapping="Wrap"/>
               </DataTemplate>
            </GridViewColumn.CellTemplate>
         </GridViewColumn>
         <GridViewColumn Header="World"/>
      </GridView>
   </ListView.View>

   <ListViewItem/>
   <ListViewItem/>
   <ListViewItem/>
   <ListViewItem/>
</ListView>
+4

-, CellTemplate - . , StackPanel CellTemplate.

. , HorizontalContentAlignment = "Stretch" ​​ ListViewItem:

<ListView.ItemContainerStyle>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
</ListView.ItemContainerStyle>
+3

, , , . , , , (a la outlook), , ,

ListViewItem ControlTemplate, TextBlock GridViewRowPresenter. , :

<Style TargetType="ListViewItem">
   <Setter Property="SnapsToDevicePixels" Value="true"/>
   <Setter Property="OverridesDefaultStyle" Value="true"/>
   <Setter Property="Template">
   <Setter.Value>
      <ControlTemplate TargetType="ListBoxItem">
         <Border Name="Border"
                 Padding="2"
                 SnapsToDevicePixels="true"
                 Background="Transparent">
            <StackPanel>
               <GridViewRowPresenter Columns="{TemplateBinding GridView.ColumnCollection}"  
                                     VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
               <TextBlock Text="This is where your text goes!"/>
            </StackPanel>
         </Border>

         <ControlTemplate.Triggers>
            <Trigger Property="IsSelected" Value="true">
               <Setter TargetName="Border"
                       Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
               <Setter Property="Foreground" 
                       Value="{StaticResource DisabledForegroundBrush}"/>
            </Trigger>
         </ControlTemplate.Triggers>
         </ControlTemplate>
   </Setter.Value>
   </Setter>
</Style>

Width TextBlock, ListView, .

+1

, .

  

            <GridView ColumnHeaderToolTip="Addendum Master" >
                    <GridViewColumn Width="500">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>                                    
                                <StackPanel Orientation="Vertical" Margin="0">
                                    <Label Content="{Binding Path=Line1}" Padding="0" Margin="0" Style="{StaticResource GridLabelStyle}"></Label>
                                    <Label Content="{Binding Path=Line2}" Padding="0" Margin="0" Style="{StaticResource GridLabelStyle}"></Label>
                                    <Label Content="{Binding Path=Line3}" Padding="0" Margin="0" Style="{StaticResource GridLabelStyle}"></Label>
                                    <Label Content="{Binding Path=Line4}" Padding="0" Margin="0" Style="{StaticResource GridLabelStyle}"></Label>
                                </StackPanel>                                                                        
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
+1

, , , 2- , .., gridview. .

  

    <Columns>                            
        <asp:BoundField DataField="CPTCode" HeaderText="CPTCode" ItemStyle-CssClass="center" SortExpression="CPTCode" >
            <ItemStyle CssClass="center" />
        </asp:BoundField>

            <asp:BoundField DataField="InsPlanCode" HeaderText="InsPlanCode" ItemStyle-CssClass="center" SortExpression="InsPlanCode" >
            <ItemStyle CssClass="center" />
        </asp:BoundField>

            <asp:BoundField DataField="StartDate" HeaderText="Start Date" ItemStyle-CssClass="center" SortExpression="StartDate" >
            <ItemStyle CssClass="center" />
        </asp:BoundField>

            <asp:BoundField DataField="EndDate" HeaderText="End Date" ItemStyle-CssClass="center" SortExpression="EndDate" >
            <ItemStyle CssClass="center" />
        </asp:BoundField>

        <asp:BoundField DataField="UserName" HeaderText="UserName" ItemStyle-CssClass="center" >
            <ItemStyle CssClass="center" />
        </asp:BoundField>   

        <asp:TemplateField HeaderText=" " ItemStyle-CssClass="center" HeaderStyle-BackColor="AliceBlue" ItemStyle-BackColor="AliceBlue">                                
            <ItemTemplate>        

                </td>
                </tr>
                <tr>
                    <td align="center" nowrap>&nbsp;<b>Message</b>&nbsp;</td>
                    <td colspan="10"><TABLE cellpadding=5><tr><td><%# Eval("carveOutMessage")%></td></tr></TABLE>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>

</asp:GridView>

TemplateField ItemTemplate.

, , , , html TemplateField, TD. . , ItemTemplate. , , td ", " ". . , - . columnspan = 10 . Templatefield TD, td , TR, , .

I hope this helps and is understandable by people. You can use this method to create as many rows as required for each record. Also do any number of other formatting actions if you are good at html and tables. The key is to remember that when you start, you format inside the open td and tr tag, and in the end it will write in the closing td and tr tag to leave your last column and row open.

0
source

Source: https://habr.com/ru/post/1718909/


All Articles