将conconst值绑定到表

时间:2014-11-03 13:45:04

标签: wpf xaml

假设我有一个表4x4,没有更多/更少的行和列。值来自代码中的计算。 here

创建它并绑定数据的最佳方法是什么? 使用datagrid还是table

我将数据网格用于列但不确定如何处理行。

<DockPanel>
        <DataGrid Name="dgTest" AutoGenerateColumns="False" IsReadOnly="True" CanUserResizeColumns="True" CanUserAddRows="False" ItemsSource="{Binding}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="IVR" Binding="{Binding IVR}" />
                <DataGridTextColumn Header="Payment" Binding="{Binding Payment}" />
                <DataGridTextColumn Header="Call" Binding="{Binding Call}" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>

编辑:2014年11月10日上午10点08分

根据迈克的评论,我做了一个改变。

    <DockPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
            </Grid.RowDefinitions>
            <TextBox Grid.Column="1">IVR</TextBox>
            <TextBox Grid.Column="2">PAYMENT</TextBox>
            <TextBox Grid.Column="3">CALL</TextBox>
            <TextBox Grid.Row="1">SUCCESS</TextBox>
            <TextBox Grid.Row="2">FAIL</TextBox>
            <TextBox Grid.Row="3">TOTAL</TextBox>
        </Grid>
    </DockPanel>

然后如何绑定值?

1 个答案:

答案 0 :(得分:0)

感谢Mike Strobel,我使用Grid加上文本框。

   <DockPanel Margin="20">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
                <RowDefinition Height="20" />
            </Grid.RowDefinitions>
            <TextBox Grid.Column="0" />
            <TextBox Grid.Column="1">IVR</TextBox>
            <TextBox Grid.Column="2">PAYMENT</TextBox>
            <TextBox Grid.Column="3">CALL</TextBox>
            <TextBox Grid.Row="1">SUCCESS</TextBox>
            <TextBox Grid.Row="2">FAIL</TextBox>
            <TextBox Grid.Row="3">TOTAL</TextBox>
            <TextBox Text="{Binding Path=IVR_S}" Grid.Row="1" Grid.Column="1" />
            <TextBox Text="{Binding Path=PAYMENT_S}" Grid.Row="1" Grid.Column="2" />
            <TextBox Text="{Binding Path=CALL_S}" Grid.Row="1" Grid.Column="3" />
            <TextBox Text="{Binding Path=IVR_F}" Grid.Row="2" Grid.Column="1" />
            <TextBox Text="{Binding Path=PAYMENT_F}" Grid.Row="2" Grid.Column="2" />
            <TextBox Text="{Binding Path=CALL_F}" Grid.Row="2" Grid.Column="3" />
            <TextBox Text="{Binding Path=IVR-T}" Grid.Row="3" Grid.Column="1" />
            <TextBox Text="{Binding Path=PAYMENT-T}" Grid.Row="3" Grid.Column="2" />
            <TextBox Text="{Binding Path=CALL-T}" Grid.Row="3" Grid.Column="3" />
        </Grid>
    </DockPanel>