0

I have a list of mail I generate, and displayings some details into a dataGrid.

Some will works, some will be in errors.

I want to display, into the last datagrid column, a button, if the process successed, or an image if the process failed.

So, I got this with juste a button :

 <sdk:DataGridTemplateColumn Header="Voir">
   <sdk:DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
          <Button Name="btOpen" 
                  Click="btOpen_Click"
                  IsEnabled="True"/>
          </DataTemplate>
     </sdk:DataGridTemplateColumn.CellTemplate>
 </sdk:DataGridTemplateColumn>

This button will open the document.

But as I said, some process can fail, so instead of a button, I must display an image.

Can I add an image into my datagridTemplateColumn, and then displying one of them depending on the success or fail of the process(easy to know)?

If I can't, how can I do what I want here? Can I do it without adding to different columns?

Thank you.

provençal le breton
  • 1,428
  • 4
  • 26
  • 43

2 Answers2

0

You can add the image alongside the Button and bind the visibility of each of them to the success / fail of the process

Raz Abramov
  • 181
  • 12
0

Try to create two different templates on xaml. One with the image, one with the button. Then on runtime you can change it according to your needs.

<Grid.Resources>
 <DataTemplate x:key="ImageDT">
    <Image>
 </DataTemplate>

 <DataTemplate x:key="ButtonTemplate">
    <Button>
 </DataTemplate>

 </Grid.Resources>

Then on runtime, maybe on Load/LoadingRow event

//Here you get the row or column or cell you need

if(ProcessSuccess)
   Grid.Columns["Voir"].CellTemplate = Grid.Resources["ImageDT"] ;
else 
   Grid.Columns["Voir"].CellTemplate = Grid.Resources["ButtonTemplate"];

Please note that i`m not giving you the right code and only the idea.

Hope it helps

Vinicius
  • 541
  • 3
  • 15