2012-05-31 3 views
2

도움이 필요하며 올바른 방향으로 향해야합니다. 2 차원 데이터를 표시해야하는 WPF 응용 프로그램을 만들고 있습니다. 이는 다음과 같이 표시한다 :표에서 2D 데이터 시각화

------------------------- 
|y/x| 1 | 2 | 3 | 4 | 5 | 
| 1| 1 | 2 | 3 | 4 | 5 | 
| 2| 2 | 4 | 6 | 8 | 10| 
| 3| 3 | 6 | 9 | 12| 15| 
| 4| 4 | 8 | 12| 16| 20| 
| 5| 5 | 10| 15| 20| 25| 
------------------------- 

샘플 코드 : XAML :

<Window x:Class="WpfApplication6.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525" 
     DataContext="{Binding RelativeSource={RelativeSource Self}}"> 
    <Grid> 
     <!--Place control for 2d data here--> 
    </Grid> 
</Window> 

C 번호 :

public partial class MainWindow : Window 
    { 
     string[,] values = new string[5,5]; 
     string[] x = new string[5]; 
     string[] y = new string[5]; 

     public MainWindow() 
     { 
      InitializeComponent(); 
      CreateArrays(); 
     } 

     private void CreateArrays() 
     { 
      for (int i = 0; i < values.GetLength(0); i++) 
      { 
       for (int j = 0; j < values.GetLength(1); j++) 
       { 
        values[i, j] = ((i+1) * (j+1)).ToString(); 
       } 
      } 

      for (int i = 0; i < x.GetLength(0); i++) 
      { 
       x[i] = (i+1).ToString(); 
      } 

      for (int j = 0; j < y.GetLength(0); j++) 
      { 
       y[j] = (j+1).ToString(); 
      } 

     } 
    } 

그래서 첫 번째 행의 X 값을 수 있고, 첫 번째 열 y 값과 나머지는 값입니다. 상단 왼쪽 셀에 "y/x"가 있음에 유의하십시오. 머리글을 클릭하는 등 데이터를 정렬 할 가능성이 없기를 바랍니다. 클립 보드에 데이터를 복사하기 위해 여러 행이나 열을 한 번에 선택할 수있는 기능이 필요합니다. 데이터를 편집 할 수 없습니다. 또한 어떤 스타일링은 첫 번째 행과 첫 번째 열이 다른 배경색을 가져야하는 것처럼 좋을 것입니다.

어떻게해야합니까?

답변

0

이 시도 :

<Grid> 
    <ItemsControl x:Name="itemscontrol"> 
     <ItemsControl.ItemsPanel> 
      <ItemsPanelTemplate> 
       <UniformGrid Columns="6" Rows="6" /> 
      </ItemsPanelTemplate> 
     </ItemsControl.ItemsPanel> 
     <ItemsControl.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <TextBlock Text="{Binding}" Margin="5" /> 
       </Grid> 
      </DataTemplate> 
     </ItemsControl.ItemTemplate> 
    </ItemsControl> 
</Grid> 

을하고 그것으로 데이터를 가져 오는 다양한 방법이있다 - 예를 들어이

이 작동하지만 선택처럼, 내게 필요한 모든 기능을 제공하지 않습니다
public MainWindow() 
{ 
    InitializeComponent(); 
    this.itemscontrol.ItemsSource = new[] {"x/y", "1","2","3","4","5", 
              "1","1","2","3","4","5", 
              "2","2","4","6","8","10", 
              "3","3","6","9","12","15", 
              "4","4","8","12","16","20", 
              "5","5","10","15","20","25"}; 
} 
+0

여러 셀, 특정 행, 열, 셀 등의 배경을 변경합니다. – metacircle

+0

당신을위한 출발점이되어야합니다. –