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
3166
How to setup CellValuePresenter style programmatically with Binding to differrent field
posted

I have dynamic number of columns which are bound to the grid. The columns are pairs Value/State. I want to style the CellValuePresenter  for 'Value' to bind certain dependency properties based on 'State'. Since the number or columns are determined at runtime, I can't do it xaml, I need to do it programmatically.

I have created a sample where I am doing it in xaml.

<igDP:Field Name="OneValue" Label="One" >
    <igDP:Field.Settings>
        <igDP:FieldSettings>
            <igDP:FieldSettings.CellValuePresenterStyle>
                <Style TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{StaticResource {x:Type igDP:CellValuePresenter}}">
                    <!--NOTE Binding to different field xxxStale 'Path=DataItem.OneStale'-->
                    <Setter Property="Background"
                        Value="{Binding
                        Path=DataItem.OneStale,
                                Converter={StaticResource BooleanToBrushConverter}}"></Setter>
                 </Style>
            </igDP:FieldSettings.CellValuePresenterStyle>
        </igDP:FieldSettings>
    </igDP:Field.Settings>
</igDP:Field>

Note, in the sample the columns are not dynamic.

BindingDifferentFieldToCellValuePresenterStyle.zip
  • 35319
    posted

    Hi Bhavesh,

     

    I am juist checking if you require any further assistance on this matter.

  • 35319
    posted

    Hello Bhavesh,

     

    Thank you for your post. I have been looking into your question and the following code shows how to write the CellValuePresenter style for the first field in code-behind :

     

    Style MyStyle = new Style(typeof(CellValuePresenter));

    Binding myBinding = new Binding() { Path = new PropertyPath("DataItem.OneStale"), Converter = new BooleanToBrushConverter() };

    MyStyle.Setters.Add(new Setter(CellValuePresenter.BackgroundProperty, myBinding));

    xamDataGrid1.FieldLayouts[0].Fields[0].Settings.CellValuePresenterStyle = MyStyle; 

     

    You can make this style generation in a method and invoke it with the appropriate parameters for the corresponding field.

     

    Let me know, if you need any further assistance on this matter.