XAML 视图列中文本框的外观应与列表行的外观相同

myzjeezk  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(104)

我的ListView每列包含一个文本框,用于更改数据。通过样式,我的ListView行将根据交替索引以不同的颜色着色。
我希望列表视图中的文本框看起来像整行。
其实其是这样的:

线条应覆盖文本框。
为ListView行着色的代码:

<Style x:Key="DifAlternationColorsLV" TargetType="{x:Type ListViewItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="#FFB1E4EF"></Setter>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="#FFD4EBFF"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

视图的XAML中的代码:

<Border Grid.Row="1" Grid.Column="0" 
            Margin="10,10,10,10"
            BorderBrush="#FF474A57" 
            CornerRadius="10,10,10,10" 
            BorderThickness="2,2,2,2"
            Width="300"
            MaxHeight="200"
            Background="White">
        <StackPanel Margin="0,0,0,20" Orientation="Vertical">
            <StackPanel Grid.Column="0" Grid.RowSpan="1"
                Grid.Row="1"
                VerticalAlignment="Top">
                <Label HorizontalAlignment="Center" FontWeight="Bold">
                    Schichten
                </Label>
                <ListView x:Name="Shift" MinHeight="150" MaxHeight="150" MinWidth="250" HorizontalContentAlignment="Stretch" HorizontalAlignment="Center"
                      IsSynchronizedWithCurrentItem="True"
                          ItemContainerStyle="{StaticResource DifAlternationColorsLV}"
                          AlternationCount="2"
                          ItemsSource="{Binding UiShiftHModelList, UpdateSourceTrigger=PropertyChanged}"
                          SelectedItem="{Binding SelectedLine, UpdateSourceTrigger=PropertyChanged}" d:ItemsSource="{d:SampleData ItemCount=3}">
                    <ListView.View>
                        <GridView>
                            <GridView.Columns>
                                <GridViewColumn Header="Bezeichnung" Width="Auto">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox x:Name="Bezeichnung" MinWidth="100"
                                                     
                                                     Style="{StaticResource TBoxInListV}"
                                                     Text="{Binding Bezeichnung, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                                     BorderThickness="0">
                                            </TextBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn Header="Tagmuster" Width="80">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <!---->
                                            <TextBox x:Name="Tagmuster" MinWidth="80"
                                                     Background="{Binding ElementName=Shift}"
                                                     Style="{StaticResource TBoxInListV}"
                                                     Text="{Binding TagmusterID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                                      
                                                     BorderThickness="0">
                                            </TextBox>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn Header="Edit" Width="40">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" >
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Button  x:Name="SaveShiftH" 
                                                             Style="{StaticResource BtnListSave}"
                                                             Grid.Column="0">
                                                    </Button>
                                                    <Button  x:Name="UpdateShiftH" 
                                                              Style="{StaticResource BtnListUpdate}"
                                                             Grid.Column="0">
                                                    </Button>
                                                    <Button x:Name="DeleteShiftH" 
                                                             Style="{StaticResource BtnListDelete}"
                                                             Grid.Column="1">
                                                    </Button>
                                                    <Button x:Name="ReopenShiftH"  
                                                            Style="{StaticResource BtnListReopen}"
                                                             Grid.Column="0">
                                                    </Button>
                                                </Grid>
                                            </StackPanel>
                                            <DataTemplate.Triggers>
                                                <!--Visibility of the Buttons-->
                                                <DataTrigger Binding="{Binding EditModus}" Value="0">
                                                    <Setter TargetName="SaveShiftH" Property="Visibility" Value="Visible"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding EditModus}" Value="2">
                                                    <Setter TargetName="UpdateShiftH" Property="Visibility" Value="Visible"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding EditModus}" Value="1">
                                                    <Setter TargetName="UpdateShiftH" Property="Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding EditModus}" Value="2">
                                                    <Setter TargetName="DeleteShiftH" Property="Visibility" Value="Visible"/>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding EditModus}" Value="1">
                                                    <Setter TargetName="DeleteShiftH" Property="Visibility" Value="Collapsed"/>
                                                </DataTrigger>
                                            <!--<DataTrigger Binding="{Binding EditModus}" Value="0">
                                                    <Setter TargetName="Delete" Property="Visibility" Value="Collapsed"/>
                                                </DataTrigger>-->
                                                <DataTrigger Binding="{Binding EditModus}" Value="1">
                                                    <Setter TargetName="ReopenShiftH" Property="Visibility" Value="Visible"/>
                                                </DataTrigger>
                                            </DataTemplate.Triggers>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>
                            </GridView.Columns>
                        </GridView>
                    </ListView.View>
                </ListView>
            </StackPanel>
        </StackPanel>
    </Border>

如果我将[文字方块]的[背景系结]变更为:

Background="{Binding ElementName=Shift}"

这条线完全符合我的要求,但会导致很多绑定错误。

有什么想法吗?

v1uwarro

v1uwarro1#

可以使TextBox的背景完全或部分透明;使行的背景可见:

<TextBox x:Name="Bezeichnung" MinWidth="100" Background="#60FFFFFF"
        Style="{StaticResource TBoxInListV}"
        Text="{Binding Bezeichnung, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
        BorderThickness="0">
    </TextBox>

相关问题