0

我阅读了很多关于 listView 的内容但仍然无法理解......我定义了以下 5 列的 listView,第一个是标签,其余的是 texbox。我需要添加 13 行,每个文本框和标签都需要绑定到不同的东西。所以我知道 listViewItem 不会这样做,因为列表中的每个对象都绑定到其他东西。谢谢你的帮助。

<ListView DockPanel.Dock="Top" Width="607" Height="400" Margin="10 0" HorizontalAlignment="Left"
          ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="1" Width="120" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Label/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="2" Width="120" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="3" Width="120" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="4" Width="120" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="5" Width="120" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
4

2 回答 2

0

你真的不想做这样的事情吗?

    <Grid Height="100" HorizontalAlignment="Left" Margin="22,62,0,0" Name="listBox1" VerticalAlignment="Top" Width="607">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width='120'/>
            <ColumnDefinition Width='120'/>
            <ColumnDefinition Width='120'/>
            <ColumnDefinition Width='120'/>
            <ColumnDefinition Width='120'/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height='30'/>
            <RowDefinition Height='30'/>
        </Grid.RowDefinitions>

        <!-- ROW 0-->
        <Label Grid.Column='0' Grid.Row='0' Content=' your lable' Height="28"/>
        <TextBox  Grid.Column='1' Grid.Row='0' Text='Text01'/>
        <TextBox  Grid.Column='2' Grid.Row='0' Text='Text02'/>
        <TextBox  Grid.Column='3' Grid.Row='0' Text='Text03'/>
        <TextBox  Grid.Column='4' Grid.Row='0' Text='Text04'/>

        <!--Row 1-->
        <Label Grid.Column='0' Grid.Row='1' Content=' your lable' Height="28"/>
        <TextBox  Grid.Column='1' Grid.Row='1' Text='Text01'/>
        <TextBox  Grid.Column='2' Grid.Row='1' Text='Text02'/>
        <TextBox  Grid.Column='3' Grid.Row='1' Text='Text03'/>
        <TextBox  Grid.Column='4' Grid.Row='1' Text='Text04'/>
    </Grid>
于 2013-05-28T08:03:06.547 回答
0

我最终在列表中的每个项目中都做了一个网格,如下所示:

<ListView  DataContext="{Binding CurrentMonitorCalib}"  Grid.Column="5" Grid.Row="3" Height="488"  Width="444" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
    <ListView.View>
        <GridView>                 
            <GridViewColumn Header="Cal Point" Width="80"/>
            <GridViewColumn Header="Source" Width="90" />
            <GridViewColumn Header="Failure Limit" Width="90" />
            <GridViewColumn Header="Reference" Width="90" />
            <GridViewColumn Header="# DaysLimit" Width="90" />
        </GridView>
    </ListView.View>
    <ListViewItem>
        <Grid Width="441" Margin="-359,0,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="81" />
                <ColumnDefinition Width="91" />
                <ColumnDefinition Width="91" />
                <ColumnDefinition Width="91" />
                <ColumnDefinition Width="91" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
            <Label Content="Zero" Margin="5,0" />
                <TextBox Grid.Column="1" Text="{Binding Path=ZeroSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <TextBox Grid.Column="2" Text="{Binding Path=ZeroFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
            <TextBox Grid.Column="3" Text="{Binding Path=ZeroRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"  />
            <TextBox Grid.Column="4" Text="{Binding Path=ZeroZNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
        </Grid>
    </ListViewItem>
            <ListViewItem>
                <Grid Width="442" Margin="-359,0,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="81" />
                        <ColumnDefinition Width="91" />
                        <ColumnDefinition Width="91" />
                        <ColumnDefinition Width="91" />
                        <ColumnDefinition Width="91" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <Label Content="Span" Margin="5,0"/>
                    <TextBox Grid.Column="1" Text="{Binding Path=SpanSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBox Grid.Column="2" Text="{Binding Path=SpanFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
                    <TextBox Grid.Column="3" Text="{Binding Path=SpanRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"  />
                    <TextBox Grid.Column="4" Text="{Binding Path=SpanNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"  Margin="0,0,8,7" />                    
                </Grid>
            </ListViewItem>

等等......感谢您的帮助!

于 2013-06-03T06:44:31.560 回答