2015-06-11 39 views
2

我想創建一個只包含一個表,但表不顯示的表,它只是說「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/> 

這裏沒什麼特別的,但是當我構建解決方案時,唯一的r我得到的是這樣的: Running Program

我錯過了什麼?

+0

你在.cs文件中有什麼? –

+0

絕對沒有。迄今爲止,它是純xa​​ml。 –

回答

2

System.Windows.Documents.Table無法用您期望的結果託管任何容器(您的情況爲UserControl)。這就是爲什麼它只是調用ToString()方法來顯示目的,導致你看到的字符串。

查看類的備註部分。它列出了Table的合適父母容器。 Table用於文檔結構。

如果要在網格結構中顯示有序數據,DataGrid應該是一個合適的解決方案。

如果你只是想用類似表格的結構來佈局你的表格來放入其他控件,那麼Grid類將會是你正在尋找的。

+1

噢好吧,你是對的DataGrid將是一個更有用的塊在我的情況下使用。它看起來像表不完全按照我想要的那樣行事,閱讀這裏的註釋https://msdn.microsoft.com/en-us/library/ms747133%28v=vs.110%29.aspx,似乎該表只能在FlowDocument中使用 –