Hello, I am working to get a XamDataGrid to use dynamic created columns. Following the Blog https://ko.infragistics.com/community/blogs/blagunas/archive/2012/10/24/xamdatagrid-dynamically-create-and-data-bind-columns-with-an-editor-of-your-choice.aspxI was able to get some things done.1. UnboundField vs. Field// worksvar field1 = new UnboundField();field1.Name = tag.ID;field1.AllowRecordFiltering = false;field1.BindingPath = new PropertyPath(string.Format("Tage[{0}].KompaktAE", counter));field1.Label = new Binding{ Path = new PropertyPath(string.Format("Tage[{0}].Datum", counter))};field1.CellValuePresenterStyle = (Style)this.Arbeitseinteilung.Resources["AEStyle"];// Does not work - it does not contain any datavar field = new Field();field.Name = tag.ID;field.BindingType = BindingType.UseNameBinding;field.Label = tag.TagKurz;field.AllowRecordFiltering = false;field.AlternateBinding = new Binding{ Path = new PropertyPath(string.Format("Tage[{0}].KompaktAE", counter)), Mode = BindingMode.TwoWay};field.CellValuePresenterStyle = (Style)this.Arbeitseinteilung.Resources["AEStyle"];e.FieldLayout.Fields.Add(field);2. How to set the binding for the labelIn XAML it looks like this: <igDP:Field Label="{Binding Path=Data.Kalender[0].Tag, Source={StaticResource Proxy} }" AlternateBinding="{Binding Path=Tage[0].KompaktAE}" BindingType="UseAlternateBinding" CellValuePresenterStyle="{StaticResource AEStyle}" />BindingOperations.SetBinding(field1, Field.LabelProperty,new Binding(string.Format("Tage[{0}].Datum", counter) ) ); Path = new PropertyPath(string.Format("Data.Kalender[{0}].Tag", counter)), Source = "{StaticResource Proxy}"Proxy is a link to the ViewModel.3. How to apply a style with a MultiBindingConverter:<Setter Property="Background"> <Setter.Value> <MultiBinding Converter="{StaticResource ArbeitseinteilungFarbe}" FallbackValue="Brushes.Yellow"> <Binding Path="DataItem" /> <Binding RelativeSource="{RelativeSource Self}" /> <Binding Source="{StaticResource Proxy}" Path="Data.Kalender" /> </MultiBinding> </Setter.Value></Setter>a) Binding Path="DataItem" gives me the current recordb) Binding RelativeSource="{RelativeSource Self}" returns the DataPresenterc) Binding Source="{StaticResource Proxy}" Path="Data.Kalender" returns the property Kalender of the ViewModelThese are ok, but I also need the current cell.Reason - In order to paint the background in the correct way following data is needed:a) the current record = empyloyee -> OKb) the calender, what is the working time every day -> OKc) the current cell to get the color of the currrent assignment -> OPEN
Thanks
Niko
Hello Nikolaus,
I apologize for the delay in my response on this matter, as I was unfortunately not notified of the updates to this forum thread. I will begin with your new inquiries asked on 6-26-2017.
1. Since you are currently trying to bind to a complex property path, you will not be able to use a name-binding in this case, unless you were to create a property directly on your underlying data item that returned the value that you are looking to bind to. Since it appears that you may not necessarily know the amount of items in your “Tage” collection, though, this likely is not an option for you. I would recommend continuing with an alternate binding in this case, as nested path name-bindings are currently not supported in the XamDataGrid.
2. In order to get a list of selected cells, I would recommend utilizing the XamDataGrid.SelectedItems.Cells collection. This will give you a full list of the cells that are selected in the grid. If you would like to know when this collection changes, I would recommend hooking into the XamDataGrid.SelectedItems.Cells.CollectionChanged event.
Moving on to your post on 7-8-2017, it appears that you were able to get the tooltips working as per your post on 7-10-2017. I am rather unsure why the string.Format property path is not working for you in this case, but as an alternative, perhaps you could consider setting up your “bindingName” variable like so:
string bindingName = “Tage[“ + counter.ToString() + “].KompaktAE”;
This should be the same thing that is being returned from your string.Format procedure, but I am not entirely sure at the moment. If the Tage collection exists as a property on the data items currently bound to your XamDataGrid, I would expect that this works, and I have verified this on my end by isolating a scenario like yours.
Regarding your most recent update to this forum thread, I will answer you inquiries in the order they were asked:
1. In order to configure a context menu for a particular field, I would recommend that you use a similar method to the one that you are using for your tooltips, in that you can specify a ContextMenu using the CellValuePresenter.ContextMenu property. Assigning your style to the CellValuePresenterStyle property of the field that you wish to show your context menu on should allow you to show this menu on that field specifically.
2. I am not entirely sure I understand your requirement in this question. You are referring to an input binding, but what type of input are you looking to bind, and what are you looking to bind it to?
3. When the mouse is pressed on the FieldGroupLabelPresenter, it is captured. In this case, I would recommend continuing with an EventSetter, as the one you have provided will not work because the FieldGroupLabelPresenter does not have an event named “PreviewMouseMoveEvent.” You may be able to target the “PreviewMouseMove” rather than “PreviewMouseMoveEvent” in this case, but I would actually recommend that you simply target the “PreviewMouseDown” event and mark it handled. In doing so, you can prevent the field group from moving.
I have attached a sample project to demonstrate the recommendations above. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hello Andrew,
can you please look at the follow up questions in the thread below?
Nikolaus Kern
some new aspects came allong:
1. How can I configure a context menu for a spefic field (= column). Currently they are on the level of the XamDataGrid, but I need to have a context menu on the fields generated in code behind and no context menu for the XAML generated ones.
2. A similar question is about input binding: The XAML generatered fields should have the inputbinding to open details about the current employee, the code behind generated ones should have different inputbindings.
3. The fieldgroup (btw: A very nice feature!) can have a style for the Type FieldGroupLabelPresenter. This style does not allow to use and Eventsetter:
<EventSetter Event="PreviewMouseMoveEvent" Handler="PreventColumnMoveMove" />
I want to prevent that the FieldGroup is moved.
void PreventColumnMoveMove(object sender, MouseEventArgs e) { if (e.MouseDevice.LeftButton == MouseButtonState.Pressed) { e.Handled = true; } }
Please let me know how these issues can be resolved.
I figured a way out (together with another developer) to create a ToolTip:
var TooltipSetter = new Setter() { Property = CellValuePresenter.ToolTipProperty, Value = new Binding(string.Format("DataItem.Tage[{0}].GesamteEinteilung", counter)) { Converter = new TooltipConverter() } }; field.CellValuePresenterStyle.Setters.Add(TooltipSetter);The converter is used to supress the ToolTip when the binding is empty.I still would like to understand the reason why the binding for the whole column works with alternate binding but not with name based binding.ThanksNiko
the work is moving forward and new question arrise ;-)
I would like to add a tooltip to the fields that arr generated in the code behind:
var field = new Field(); string bindingName = string.Format("Tage[{0}].KompaktAE", counter); field.Name = bindingName; field.BindingType = BindingType.UseAlternateBinding; field.AlternateBinding = new Binding { Path = new PropertyPath(bindingName) };The property I want to bind to is Tage[{0}].GesamteEinteilung. Can you please share the correct syntaxt to get this working?ThanksNiko