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
320
Image into a boolean field
posted

 Hello,

 I'm looking forword to find a way to display an image into a boolean field. I found some posts to display an image when the field contains the path but not with a boolean value.

 So as the value is "True" I want to displai Image1.png and as the value is "False" I want to display Image2.png

 

Thanks

Parents
No Data
Reply
  • 320
    posted

     I found a solution but I don't think this way is the best...

    This solution works for me because I'm using a BindingList of known object, it's possible to insert some data in the grids that are not coming from object...

    Here is it :

    First of all, you have to put your image into the Ressouces of you project, in Application.Resources like this

    <Image Source="..." />

    As I found in the stand alone help (in Displaying on image into a Field) we have to create a special CellValuePresenter, I took the one I found in the help : 

                <Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="FlagField">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                                <Grid  Height="20">
                                    <Image
                          Margin="{TemplateBinding Padding}"
                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                          Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

    After that, create an UnboundField into the grid like this

                             <igDP:UnboundField Name="ImageField" Label="Image">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings CellMinWidth="100" CellMaxWidth="300" CellValuePresenterStyle="{StaticResource FlagField}" />
                                </igDP:Field.Settings>
                            </igDP:UnboundField>

      Add an event handler for InitializeRecord in you grid like this :

       InitializeRecord="MyXamDataGrid_InitializeRecord"

    So in the handler :

                DataRecord dr = e.Record as DataRecord;
                if (dr != null)
                {
                    MyObject obj = dr.DataItem as MyObject;
                    Cell cell = dr.Cells["ImageField"];
                    Image img;
                    if (obj .TheBooleanField == true)
                        img = (Image)App.Current.FindResource("GreenFlag");
                    else
                        img = (Image)App.Current.FindResource("RedFlag");
                    cell.Value = img.Source;
                }

    The trick is done !

    As i say, there is perhaps a best way to proceed but I haven't found it.... So... This solution works pretty well !

    I hope that the Infragistics team will comment this solution and give a best solution (if there is...)

    gle

Children