2012-07-04 2 views
0

안녕하세요 세상 - DataViewDataGrid에 표시하려고합니다. 추가 할 내용은 무엇입니까? 결과 창에있는 DataGrid는 아무 것도 표시되지 않습니다.DataGrid 안녕하세요 세계에 DataView 표시

MainWindow.xaml.cs를 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.Data; 

namespace WpfApplication3 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public DataView Displayed 
     { 
      get 
      { 
       DataTable table = new DataTable(); 
       table.Columns.Add("Col1", typeof(string)); 
       table.Columns.Add("Col2", typeof(string)); 
       table.Columns.Add("Col3", typeof(string)); 

       for (int i = 0; i < 100; i++) 
       { 
        DataRow row = table.NewRow(); 
        row["Col1"] = i.ToString() + "col1"; 
        row["Col2"] = i.ToString() + "col2"; 
        row["Col3"] = i.ToString() + "col3"; 
        table.Rows.Add(row); 
       } 

       return table.DefaultView; 
      } 
     } 

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

MainWindow.xaml :

<Window x:Class="WpfApplication3.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" 
     Title="MainWindow" Height="350" Width="525"> 
    <StackPanel> 
     <toolkit:DataGrid ItemsSource="{Binding Path=Displayed, Mode=OneWay}"> 
     </toolkit:DataGrid> 
    </StackPanel> 
</Window> 

출력 창 :

'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'c:\users\xxx\documents\visual studio 2010\Projects\WpfApplication3\WpfApplication3\bin\Debug\WpfApplication3.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
The thread 'vshost.NotifyLoad' (0x1dac) has exited with code 0 (0x0). 
The thread '<No Name>' (0x1990) has exited with code 0 (0x0). 
The thread 'vshost.LoadReference' (0x824) has exited with code 0 (0x0). 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'c:\users\xxx\documents\visual studio 2010\Projects\WpfApplication3\WpfApplication3\bin\Debug\WpfApplication3.exe', Symbols loaded. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
Step into: Stepping over non-user code 'WpfApplication3.App.App' 
Step into: Stepping over non-user code 'WpfApplication3.App.InitializeComponent' 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'c:\users\xxx\documents\visual studio 2010\Projects\WpfApplication3\WpfApplication3\bin\Debug\WPFToolkit.dll' 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 
'WpfApplication3.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 

결과 :

Result screenshot showing empty DataGrid

Displayed에 정의 된 데이터를보고 싶습니다.

답변

0

DataContextMainWindow으로 설정해야합니다. 그렇지 않으면 Displayed을 찾을 수 없습니다.

<Window DataContext="{Binding RelativeSource={RelativeSource Self}}" 
XAML

에서

public MainWindow() 
{ 
    InitializeComponent(); 
    this.DataContext = this; 
} 

동일