Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2090
XamDataGrid: UnboundField vs. Field in dynamically created columns
posted

Hello,
                
I am working to get a XamDataGrid to use dynamic created columns. Following the Blog
https://es.infragistics.com/community/blogs/blagunas/archive/2012/10/24/xamdatagrid-dynamically-create-and-data-bind-columns-with-an-editor-of-your-choice.aspx

I was able to get some things done.

1. UnboundField vs. Field
// works
var 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 data
var 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 label
In 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 record
b) Binding RelativeSource="{RelativeSource Self}" returns the DataPresenter
c) Binding Source="{StaticResource Proxy}" Path="Data.Kalender" returns the property Kalender of the ViewModel

These 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 -> OK
b) the calender, what is the working time every day -> OK
c) the current cell to get the color of the currrent assignment -> OPEN

Thanks

Niko