表用户控件未显示

时间:2015-06-11 17:45:10

标签: wpf xaml

我正在尝试创建一个只包含一个表的usercontrol但该表没有出现,它只是说" System.Windows.Documents.Table"。

我正在创建用户控件并将表格放入其中:

<UserControl x:Class="WpfApplication4.TestTableControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Table>
    <Table.Columns>
        <TableColumn/>
        <TableColumn/>
        <TableColumn/>
    </Table.Columns>
    <!-- Header -->
    <TableRowGroup>
        <TableRow FontWeight="Bold">
            <TableCell>
                <Paragraph>Head1</Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>Head2</Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>Head3</Paragraph>
            </TableCell>
        </TableRow>
        <TableRow>
            <TableCell>
                <Paragraph>1</Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>2</Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>3</Paragraph>
            </TableCell>
        </TableRow>
    </TableRowGroup>
</Table>

然后从我的测试项目中,我正在调用我的控件:

<Window x:Class="WpfApplication4.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clr-namespace:WpfApplication4"
    Title="MainWindow" Height="350" Width="525">
<my:TestTableControl/>

这里没什么特别的,但是当我构建解决方案时,我得到的唯一结果是: Running Program

我错过了什么?

1 个答案:

答案 0 :(得分:2)

System.Windows.Documents.Table无法与任何容器(您的情况下为UserControl)所期望的结果一起托管。这就是为什么它只是调用ToString()方法进行显示,从而产生你看到的字符串。

查看Table类的备注部分。它列出了Table的合适父母容器。 Table用于类似文档的结构。

如果您想在网格结构中显示有序数据,DataGrid将是一个合适的解决方案。

如果您只想使用类似于表的结构来布局表单以放入其他控件,Grid类将是您要查找的内容。