■ NavBarControl 클래스에서 단순 DataTable에 바인딩하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar" Width="800" Height="600" Title="NavBarControl을 단순 DataTable에 바인딩 하기" FontFamily="나눔고딕코딩" FontSize="12"> <Grid> <dxn:NavBarControl x:Name="navBarControl" ItemsSource="{Binding}" GroupDescription="Group"> <dxn:NavBarControl.Resources> <Style TargetType="dxn:NavBarGroup"> <Setter Property="Header" Value="{Binding}" /> </Style> <Style TargetType="dxn:NavBarItem"> <Setter Property="Content" Value="{Binding Path=Item}" /> </Style> </dxn:NavBarControl.Resources> </dxn:NavBarControl> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
using System.Data; using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); DataTable dataTable = new DataTable(); dataTable.Columns.Add("Group", typeof(string)); dataTable.Columns.Add("Item" , typeof(string)); for(int i = 1; i <= 2; i++) { for(int j = 1; j <= 3; j++) { dataTable.Rows.Add ( new object[] { "Group " + i.ToString(), "Item " + i.ToString() + "-" + j.ToString() } ); } } DataContext = dataTable; } #endregion } } |