One of my properties is of a type called Country. The country has a ShortName : String and Name : String. My XamComboBox contains items of type ComboBoxDataItem with value of type Country and display path of type String (corresponding to a country's Name). The idea is that I will select a Name from the drop down, and the proper Country will be set. However, I'm finding this quite difficult to do. My XAML looks like the following:
<igDP:UnboundField Name="Country" Label="Country" BindingPath="Country.Name" BindingMode="TwoWay"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True" > <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource countriesP}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:UnboundField>
I'm displaying the country's name, which is all good. But I'd like to modify the Country property of my main Data Item. The XAML above certainly won't work, since the Binding will try to assign the Country object to country name.
How do I do this? One way, which is nasty, it to have some kind of property of my DataItem that can be set and will easily assign the proper Country object to it, but is there a clearned way to view/edit complex properties?
Thanks,
-Szymon
Hi spate146!
I am having the same problem . I have one xamDatagrid filled with objects of type BPEmployeeViewModel . This class has two properties :
I need to have this special object in order to allow for multi-selection as you have described in xamFeatureBrowser.
The property Employee has one property of type "Function" . There are several "Functions" stored in the db so I want to load all of them and throw them into a combobox in order to allow the user to select one of them . But I can't do that since I am using ( and have to use ) a complex property . I successfully managed to get all the functions to show on my xamcombobox but it appears that i can't set it . At least I defined a breakpoint on my Function property setter and nothing , the application doesn't stop there .
My Unbound Field :
<igEditors:ComboBoxItemsProvider x:Key="FunctionItemsProvider" DisplayMemberPath="Description" ValuePath="Id"/> <!-- Functions Items Style --> <Style x:Key="FunctionItemsStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource FunctionItemsProvider}" /> </Style>
<igDP:UnboundField Label="Função" Binding Path = "Employee.EmplFunction" BindingMode="TwoWay"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="True" EditorStyle="{StaticResource FunctionItemsStyle}" /> </igDP:Field.Settings> </igDP:UnboundField>
I set the combobox itemssource in code-behind ;)
Any suggestion ?
Ivan Frias
Hi Szymon,
Why are you adding an unbound field. Why not simply just use the Country bound field directly. With this there will be no need to specify BindingPath. You can use XamComboEditor to directly edit field of a custom data type, in your case Country type.
The following is what I just tried out with a sample project. It has a DataItem class which has a Country property of type Country. Both of these are defined below. XamComboEditor is used to edit the Country field directly and it all works. The style for the XamComboEditor is in code below as well. XAML portion simply defines a XamDataGrid and doesn't have any other code.
public void OnLoaded( object sender, EventArgs e ){ List<DataItem> dataSource = new List<DataItem>( ); DataItem item; item = new DataItem( ); item.Country = new Country( "a", "AA" ); dataSource.Add( item ); item = new DataItem( ); item.Country = new Country( "b", "BB" ); dataSource.Add( item ); _dp.DataSource = dataSource; ComboBoxItemsProvider countriesIP = new ComboBoxItemsProvider( ); countriesIP.Items.Add( new Country( "a", "AA" ) ); countriesIP.Items.Add( new Country( "b", "BB" ) ); countriesIP.DisplayMemberPath = "Name"; FieldSettings settings = _dp.FieldLayouts[0].Fields["Country"].Settings; settings.EditorType = typeof( XamComboEditor ); Style style = new Style( typeof( XamComboEditor ) ); style.Setters.Add( new Setter( XamComboEditor.ValueTypeProperty, typeof( Country ) ) ); style.Setters.Add( new Setter( XamComboEditor.ItemsProviderProperty, countriesIP ) ); style.Seal( ); settings.EditorStyle = style;}public class DataItem : System.ComponentModel.INotifyPropertyChanged{ private static int ID_COUNTER = 1; private int _id; private Country _country; public DataItem( ) { _id = ID_COUNTER++; } public int Id { get { return _id; } } public Country Country { get { return _country; } set { if ( _country != value ) { _country = value; if ( null != this.PropertyChanged ) this.PropertyChanged( this, new PropertyChangedEventArgs( "Country" ) ); Debug.WriteLine( "New Value = " + _country.Name ); } } } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;}public class Country{ private string _shortName, _name; public Country( string shortName, string name ) { _shortName = shortName; _name = name; } public string Name { get { return _name; } } public string ShortName { get { return _shortName; } } public override int GetHashCode( ) { return _shortName.GetHashCode( ) ^ _name.GetHashCode( ); } public override bool Equals( object obj ) { Country c = obj as Country; return null != c && _shortName == c._shortName && _name == c._name; }}
Hope this helps,
Sandip