Hi there
I know I can easily bind *to* a grid's active item by setting a binding using the ActiveRecord.DataItem property. However, how can I do it the other way round? I don't see a converter as a solution: The converter does not have a context (the grid), and this context cannot be assigned through a binding property because that would lead to a circular reference (if I declare it first, the binding fails, if I declare it later, the grid does not see the converter):
<UserControl.Resources> <!-- this binding does not work - the grid has not been created yet --> <conv:ActiveGridRowConverter x:Key="rowConverter" Grid="{Binding ElementName=contactGrid, Mode=OneTime}" /></UserControl.Resources><igDP:XamDataGrid x:Name="contactGrid" DataSource="{Binding Path=ContactStore.Contacts}" ActiveRecord="{Binding Path=ActiveContact.Contact, Converter={StaticResource rowConverter}}" />
I'm not sure whether I'm just overlooking the obvious - what's the recommended solution here?
Thanks,
Philipp
We found the way to make it work with IValueConverter.it's working fine except the highlight color is not shown on the selected row. I'm not sure why dataRecord can't create a instance and DataItem can't be set.. :(
public class ActiveGridRowConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
CurrencyEntity entity = value as CurrencyEntity;
if (entity != null)
DataRecord dataRecord;// = new DataRecord(); <<< HERE IS THE PROBLEM
//dataRecord.DataItem = entity;
// return dataRecord;
}
return null;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfoculture)
DataRecord dataRecord = value as DataRecord;
if (dataRecord != null)
CurrencyEntity entity = dataRecord.DataItem as CurrencyEntity;
return entity;
Philipp Sumi is right. XamDataGrid looks very "WinFormisch". I would prefer "WPFisch" style, like a standard WPF Selector/MultiSelector control.
Microsoft is now working on it's own DataGrid and it looks very "WPFisch". It is possible to use databinding with 0 (Zero) code. XamDataGrid can't be used without code behind. I had to write many code, only to set some property in my model.
Solution with MultiValueConverter - you don't really mean that, didn't you? Why is it not part of XamDataGrid?
Why XamDataGrid does not have a simple ActiveRecord from type Object. Why XamDataGrid does not makes the conversion itself? It knows better than I what is Record and how it can be converted back to my data objects.
<XamDataGrid ItemsSource={Binding SomeData} SelectedItem={Binding SelectedData} />
That's it. No converters, no code. Just so simple can it be.
Hi Joe,
I am having a similar problem and your reply is great for setting the ActiveRecord, but I also am in need for this to be a two way binding.
But no matter what I try the binding will only update the ActiveRecord.
Any guidance is appreciated.
Thanks in advance,
Kavan
<local:DataItemToRecordConverter x:Key="myDataItemToRecordConverter"/>
<igDP:XamDataGrid Name="xamDataGrid1" >
<igDP:XamDataGrid.ActiveRecord> <MultiBinding Converter="{StaticResource myDataItemToRecordConverter}"> <Binding ElementName="xamDataGrid1"/> <Binding Path="ActiveContact.Contact"/> </MultiBinding> </igDP:XamDataGrid.ActiveRecord>
<igDP:XamDataGrid.ActiveRecord>
<MultiBinding Converter="{StaticResource myDataItemToRecordConverter}"> <Binding ElementName="xamDataGrid1"/> <Binding Path="ActiveContact.Contact"/> </MultiBinding>
<MultiBinding Converter="{StaticResource myDataItemToRecordConverter}">
<Binding ElementName="xamDataGrid1"/> <Binding Path="ActiveContact.Contact"/>
<Binding ElementName="xamDataGrid1"/>
<Binding Path="ActiveContact.Contact"/>
</MultiBinding>
</igDP:XamDataGrid.ActiveRecord>
</igDP:XamDataGrid>
public class DataItemToRecordConverter : IMultiValueConverter
public object Convert(object[ values, Type targetType, object parameter, CultureInfo culture) { DataPresenterBase dataPresenterBase = values[0] as DataPresenterBase; if (dataPresenterBase != null) { Contact contact = values[1] as Contact; if (contact != null) return dataPresenterBase.GetRecordFromDataItem(contact, true); } return null; } public object[ ConvertBack(object value, Type[ targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException("Convert Back not implemented"); }
public object Convert(object[ values, Type targetType, object parameter, CultureInfo culture)
DataPresenterBase dataPresenterBase = values[0] as DataPresenterBase; if (dataPresenterBase != null) { Contact contact = values[1] as Contact; if (contact != null) return dataPresenterBase.GetRecordFromDataItem(contact, true); } return null;
DataPresenterBase dataPresenterBase = values[0] as DataPresenterBase;
if (dataPresenterBase != null)
Contact contact = values[1] as Contact; if (contact != null) return dataPresenterBase.GetRecordFromDataItem(contact, true); }
Contact contact = values[1] as Contact;
if (contact != null)
return dataPresenterBase.GetRecordFromDataItem(contact, true);
public object[ ConvertBack(object value, Type[ targetTypes, object parameter, CultureInfo culture)
throw new NotImplementedException("Convert Back not implemented");
Hi Joe
Your assumption is correct (I wanted to go that way because I don't see a simpler solution to setting the active record). However, ActiveContact is part of my view model and therefore unaware of grids or any other UI controls. Is it possible that the grid exposes somewhat of a design flaw here? ActiveRecord is a pretty "WinFormish" strategy and - as it appears - a one way street when it comes to binding objects. IMO, an ActiveItem property was the way to go...
Any idea for a workaround? I honestly can't imagine thatI'm the first person to set the active item through a binding expression
Cheers
Philpp