如何在MVVM模式中获取动态更改列宽的listview列行

时间:2017-07-08 06:08:18

标签: wpf listview mvvm

我在wpf中有一个列表视图,有3个组合框和2个复选框作为列。我根据一些搜索条件使用复选框可见性。我可以在行之间实现水平线,但是我无法实现垂直线来分隔列。我改变了复选框和&amp ;;的可见性。我的模型的列宽。我需要遵循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>

1 个答案:

答案 0 :(得分:0)