XamDataGridの2つの列にXamComboEditorをバインドしました。XamComboEditor1からアイテムを選択するときに、特定のアイテムをXamComboEditor2にバインドしたいと思います。SelectedItemChangedイベントをXamComboEditor1に添付しました。イベントは、アイテムを選択するとノンストップで発生します。
XAML-
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:igDP="http://infragistics.com/DataPresenter"
xmlns:igRibbon="http://infragistics.com/Ribbon"
xmlns:igOB="http://infragistics.com/OutlookBar"
xmlns:igDock="http://infragistics.com/DockManager"
xmlns:igTiles="http://infragistics.com/Tiles"
xmlns:igEditors="http://infragistics.com/Editors"
Title="Window1" Height="300" Width="720">
<Window.Resources>
</Window.Resources>
<Grid>
<DockPanel LastChildFill="True" Margin="0,26,0,-26">
<igDP:XamDataGrid x:Name="XamDataGrid1">
</igDP:XamDataGrid>
</DockPanel>
</Grid>
</Window>
コードビハインド-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 Infragistics.Windows.DataPresenter;
using Infragistics.Windows.Editors;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
EventManager.RegisterClassHandler(typeof(ValueEditor),
ValueEditor.ValueChangedEvent,
new RoutedPropertyChangedEventHandler<object>(OnValueChanged));
ComboBoxItemsProvider provider = new ComboBoxItemsProvider();
for (int i = 0; i < 6; i++)
provider.Items.Add(new ComboBoxDataItem(i, "Item " + i.ToString()));
FieldLayout fieldLayout = new FieldLayout();
UnboundField fld1 = new UnboundField();
fld1.Name = "Visibility Setting1";
Style style1 = new Style(typeof(XamComboEditor));
style1.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, provider));
style1.Setters.Add(new EventSetter(XamComboEditor.SelectedItemChangedEvent, new RoutedPropertyChangedEventHandler<object>(XamComboEditor1_SelectedItemChanged)));
fld1.Settings.EditorStyle = style1;
fld1.Settings.EditorType = typeof(XamComboEditor);
fieldLayout.Fields.Add(fld1);
UnboundField fld2 = new UnboundField();
fld2.Name = "Visibility Setting2";
Style style2 = new Style(typeof(XamComboEditor));
fld2.Settings.EditorStyle = style2;
fld2.Settings.EditorType = typeof(XamComboEditor);
fieldLayout.Fields.Add(fld2);
this.XamDataGrid1.FieldLayouts.Add(fieldLayout);
this.XamDataGrid1.BindToSampleData = true;
}
void OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (sender is XamComboEditor || sender is XamCheckEditor || sender is XamDateTimeEditor)
{
(sender as ValueEditor).EndEditMode(true, true);
if (sender is XamComboEditor)
{
XamComboEditor comboEditor = (XamComboEditor)sender;
}
}
}
private void XamComboEditor1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
// Create combo box items provider for freight modes
ComboBoxItemsProvider provider = new ComboBoxItemsProvider();
for (int i = 0; i < 10; ++i)
{
provider.Items.Add(new ComboBoxDataItem(i.ToString(), i.ToString()));
}
//// Get unbound field associated with index
Record record = this.XamDataGrid1.ActiveRecord;
// Get the combo editor with record
UnboundField uFld = (UnboundField)record.FieldLayout.Fields[1];
// Set style for uFld
Style style = new Style(typeof(XamComboEditor));
style.Setters.Add(new Setter(XamComboEditor.ItemsProviderProperty, provider));
style.Setters.Add(new Setter(XamComboEditor.DropDownResizeModeProperty, Infragistics.Windows.Controls.PopupResizeMode.None));
style.Setters.Add(new Setter(XamComboEditor.IsAlwaysInEditModeProperty, false));
style.Setters.Add(new EventSetter(XamComboEditor.SelectedItemChangedEvent, new RoutedPropertyChangedEventHandler<object>(XamComboEditor2_SelectedItemChanged)));
style.Setters.Add(new Setter(XamComboEditor.IsEditableProperty, false));
uFld.Settings.EditorStyle = style;
uFld.Settings.EditorType = typeof(XamComboEditor);
uFld.Settings.InvalidValueBehavior = InvalidValueBehavior.RetainValue;
uFld.Settings.AllowCellVirtualization = false;
e.Handled = true;
}
private void XamComboEditor2_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
}
}
}