'宣言 Public Property ItemsSource As IEnumerable
public IEnumerable ItemsSource {get; set;}
XamComboEditor のドロップダウンに表示する項目を指定できる方法は 2 通りあります。ドロップダウンに表示するために ItemsSource プロパティを項目のコレクションに設定できます。または Items プロパティを返されたコレクションに項目を追加できます。同時に両方を実行できないことに注意してください。ItemsSource プロパティを指定すると、Items プロパティは読み取り専用のコレクションを返します。これは ItemsSource として同じ項目を反映しますが、読み取り専用です。ItemsSource に行った変更も Items プロパティによって反映されます。
using Infragistics.Windows.Editors; using Infragistics.Windows.DataPresenter; public partial class Window1 : Window { public Window1() { InitializeComponent(); // the first XamComboEditor is using the ItemsProvider defined as a shared // resource in xaml this.XamComboEditor1.ItemsProvider = this.Resources["ComboItemsProvider"] as ComboBoxItemsProvider; this.XamComboEditor1.DropDownButtonDisplayMode = DropDownButtonDisplayMode.Always; this.XamComboEditor1.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(XamComboEditor1_SelectedItemChanged); // the second XamComboEditor is defining its own ItemsProvider and // making use of the ComboBoxDataItem helper class to easily define // a separate DisplayText and Value for each item. Alternatively, // you can set the ItemsSource to any IEnumerable and set the // DisplayMemberPath and ValuePath properties to achieve the same effect. ComboBoxItemsProvider provider = new ComboBoxItemsProvider(); for (int i = 0; i < 6; i++) provider.Items.Add( new ComboBoxDataItem(i, "Item " + i.ToString())); this.XamComboEditor2.ValueType = typeof(int); this.XamComboEditor2.ItemsProvider = provider; // The following shows a XamDataGrid that adds an unbound field that // sets its EditorStyle to a XamComboEditor that uses the same shared // ItemsProvider that was defined in xaml. This leverages the significant // speed and memory footprint advantages of using a single shared // ItemsProvider for each record in the XamDataGrid. Note: this can // also be used for standard bound Fields as well. UnboundField fld = new UnboundField(); fld.Name = "Visibility Setting"; Style style = new Style(typeof(XamComboEditor)); style.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, new DynamicResourceExtension("ComboItemsProvider"))); fld.Settings.EditorStyle = style; fld.Settings.EditorType = typeof(XamComboEditor); FieldLayout fieldLayout = new FieldLayout(); fieldLayout.Fields.Add(fld); this.XamDataGrid1.FieldLayouts.Add(fieldLayout); this.XamDataGrid1.BindToSampleData = true; } private void XamComboEditor1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { } }
Imports Infragistics.Windows.Editors Imports Infragistics.Windows.DataPresenter Class Window1 Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. ' the first XamComboEditor is using the ItemsProvider defined as a shared ' resource in xaml Me.XamComboEditor1.ItemsProvider = TryCast(Me.Resources("ComboItemsProvider"), ComboBoxItemsProvider) Me.XamComboEditor1.DropDownButtonDisplayMode = DropDownButtonDisplayMode.Always AddHandler Me.XamComboEditor1.SelectedItemChanged, AddressOf XamComboEditor1_SelectedItemChanged ' the second XamComboEditor is defining its own ItemsProvider and ' making use of the ComboBoxDataItem helper class to easily define ' a separate DisplayText and Value for each item. Alternatively, ' you can set the ItemsSource to any IEnumerable and set the ' DisplayMemberPath and ValuePath properties to achieve the same effect. Dim provider As ComboBoxItemsProvider = New ComboBoxItemsProvider() For i As Int32 = 0 To 8 provider.Items.Add(New ComboBoxDataItem(i, "Item " + i.ToString())) Next Me.XamComboEditor2.ValueType = GetType(Integer) Me.XamComboEditor2.ItemsProvider = provider ' The following shows a XamDataGrid that adds an unbound field that ' sets its EditorStyle to a XamComboEditor that uses the same shared ' ItemsProvider that was defined in xaml. This leverages the significant ' speed and memory footprint advantages of using a single shared ' ItemsProvider for each record in the XamDataGrid. Note: this can ' also be used for standard bound Fields as well. Dim fld As UnboundField = New UnboundField() fld.Name = "Visibility Setting" Dim styl As Style = New Style(GetType(XamComboEditor)) styl.Setters.Add(New Setter(XamComboEditor.ItemsProviderProperty, New DynamicResourceExtension("ComboItemsProvider"))) fld.Settings.EditorStyle = styl fld.Settings.EditorType = GetType(XamComboEditor) Dim fl As FieldLayout = New FieldLayout() fl.Fields.Add(fld) Me.XamDataGrid1.FieldLayouts.Add(fl) Me.XamDataGrid1.BindToSampleData = True End Sub Private Sub XamComboEditor1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Object)) End Sub End Class