Wpf 如何在MVVM模式中获取列宽动态变化的listview列线

Wpf 如何在MVVM模式中获取列宽动态变化的listview列线,wpf,listview,mvvm,Wpf,Listview,Mvvm,我在wpf中有一个列表视图,有3个组合框和2个复选框作为列。我根据一些搜索条件使用复选框可见性。我可以实现行与行之间的水平线,但是我无法实现分隔列的垂直线。我更改了模型中复选框和列宽的可见性。我需要遵循MVVM模式。 非常感谢你的帮助。 提前谢谢 下面是我的xaml代码 <ListView Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="2" ItemsSource="{Binding N

我在wpf中有一个列表视图,有3个组合框和2个复选框作为列。我根据一些搜索条件使用复选框可见性。我可以实现行与行之间的水平线,但是我无法实现分隔列的垂直线。我更改了模型中复选框和列宽的可见性。我需要遵循MVVM模式。 非常感谢你的帮助。 提前谢谢

下面是我的xaml代码

<ListView  Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="2" 
                           ItemsSource="{Binding NewTransactionSetlist,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                          SelectedItem="{Binding SelectedNewItem,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                           SelectedIndex="{Binding SelectedNewIndex, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                           VerticalAlignment="Top" Height="320"  SelectionMode="Single" 
                          HorizontalAlignment="Center" Width="1240">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                            <Setter Property="Padding" Value="0,2"/>
                            <Setter Property="BorderBrush" Value="LightGray"/>
                            <Setter Property="BorderThickness" Value="0,0,0,1"/>
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <!--<EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem" ></EventSetter>
                            <Style.Triggers>
                                    <Trigger Property="IsKeyboardFocusWithin" Value="true">
                                        <Setter Property="IsSelected" Value="true" />
                                    </Trigger>
                                </Style.Triggers>-->
                            <!--<Style.Triggers>
                                <DataTrigger Binding="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="True">
                                    <Setter Property="IsSelected" Value="True"  />
                                </DataTrigger>
                            </Style.Triggers>-->

                        </Style>
                    </ListView.ItemContainerStyle>
                    <!--<i:Interaction.Triggers>
                        <i:EventTrigger EventName="PreviewGotKeyboardFocus">
                            <i:InvokeCommandAction Command="{Binding PreviewGotKeyboardFocusCommand}" 
                                                  />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>-->
                    <!--<Style TargetType="{x:Type ListViewItem}">
                         <Style.Triggers>
                            <DataTrigger Binding="{Binding IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="True">
                                <Setter Property="IsSelected" Value="True"  />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>-->
                    <ListView.InputBindings>
                        <KeyBinding 
                         Key="Delete" 
                         Command="{Binding NewTransactionDataGridRowDeleteCommand}"/>
                    </ListView.InputBindings>
                    <ListView.View>
                        <GridView ColumnHeaderContainerStyle="{StaticResource GridViewHeaderStyle}">
                            <GridViewColumn Header="Transaction" Width="{Binding NewTransactionHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"   >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                            <ComboBox x:Name="ComboBoxParamList" HorizontalAlignment="Left" Width="{Binding TransactionHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                  IsEditable="False" Style="{DynamicResource DatagridComboboxFontstyle}" 
                                              Text="{Binding ParamGroup, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                                              SelectedValue ="{Binding ParamGroup, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                                              ItemsSource="{Binding ParamGroupList}" >
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="SelectionChanged">
                                                    <i:InvokeCommandAction Command="{Binding DataContext.ParameterNewSelectionChangedCommand, 
                                                    RelativeSource={RelativeSource AncestorType=ListView}}"/>
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </ComboBox>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="System" Width="{Binding NewSystemHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                            <ComboBox x:Name="ComboBoxSystemList"  HorizontalAlignment="Left" Width="{Binding SystemHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                  IsEditable="False" Style="{DynamicResource DatagridComboboxFontstyle}" 
                                              Text="{Binding SystemName, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                                              SelectedValue ="{Binding SystemName, Mode=TwoWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" 
                                              ItemsSource="{Binding SystemNameList}"   />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="HandAdd" Width="{Binding NewHandAddHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                            <CheckBox Name="CheckBoxNewHandAdd" Width="{Binding HandAddHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                  Visibility="{Binding HandAddVisibility,Converter={StaticResource BoolToVisConverter}}"  
                                                  IsChecked="{Binding HandAdd, Mode=TwoWay, NotifyOnSourceUpdated=True, 
                                        UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" Margin="90,0,0,0" ></CheckBox>
                                    </DataTemplate>                                        
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Downstream" Width="{Binding NewDownstreamHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                            <CheckBox Width="{Binding DownstreamHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  
                                                  Visibility="{Binding DownstreamVisibility,Converter={StaticResource BoolToVisConverter}}" 
                                                  IsChecked="{Binding Downstream, Mode=TwoWay, NotifyOnSourceUpdated=True, 
                                        UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"  Margin="90,0,0,0"></CheckBox>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Node" Width="{Binding NewNodeHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                            <ComboBox x:Name="ComboBoxNodeList" Width="{Binding NodeHeaderLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                                  Text="{Binding Node, Mode=TwoWay, NotifyOnSourceUpdated=True, 
                                        UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" 
                                                  SelectedValue ="{Binding Node, Mode=TwoWay, NotifyOnSourceUpdated=True, 
                                        UpdateSourceTrigger=PropertyChanged}"  IsEditable="False" Style="{DynamicResource DatagridComboboxFontstyle}" 
                                              ItemsSource="{Binding NodeList}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>


这个博客解决了我的问题

你想在网格上显示网格线吗?尝试在网格中设置ShowGridLines=true。我使用的是.net framework 4.6,在我的程序集中找不到它。我怎样才能得到那个dll?是的,试试这个博客,你可以用它来创建垂直和水平的网格线。谢谢伙计!它解决了我的问题。。!