views:

26

answers:

2
 <sdk:DataGridTemplateColumn>
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <StackPanel Loaded ="SPImage_Loaded" Orientation="Horizontal" Background="Transparent" >
                            <Button x:Name="myButton"   
                        Click="Btn_Click">
                            <Image  x:Name="imgMarks" " Stretch="None"/>
                        </Button>
                        </StackPanel>
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>

in .cs i have defined the event for stack panel

 private void SPImage_Loaded(object sender, RoutedEventArgs e)
    {
        try
        {
            var TargetMarks = sender as StackPanel;
            Image imgMarks= (Image)TargetScore.FindName("imgMarks");

             Marks obj = (Marks )TargetMarks.DataContext;

// here marks oject  would be  containg the  details
// here if marks.score object value  is  1 then bind the image
//else
// dnt bind the image . that is  logic i am trying to  do.

            imgMarks.Source = new BitmapImage(new Uri("/Images/a1.png", UriKind.Relative));
        }
        catch (Exception)
        {
            throw;
        }
    }

any solution on this would be great. is there any better solution to achive this. plz help me out.

thank you.

A: 

Without seeing the full xaml and .cs file, are you certain the x:Class for the user control specified in the xaml is the same as the class name in your .cs file?

James Alexander
A: 

I have used a Converter for similar things to this. Bind the Source of your image to your Marks object then decide what the Source is based on the score.

Hope it helps

Tim Heur article on Converters and DataBinding

elsharpo