Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 807935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:28:56+00:00 2026-05-15T00:28:56+00:00

this is my xaml code. <sdk:DataGrid x:Name=dgMarks CanUserResizeColumns=False SelectionMode=Single AutoGenerateColumns=False VerticalAlignment=Top IsReadOnly=True Margin=13,44,0,0 RowDetailsVisibilityChanged=dgMarks_RowDetailsVisibilityChanged

  • 0

this is my xaml code.

 <sdk:DataGrid x:Name="dgMarks"  CanUserResizeColumns="False"  SelectionMode="Single"   AutoGenerateColumns="False" VerticalAlignment="Top" IsReadOnly="True"  Margin="13,44,0,0" RowDetailsVisibilityChanged="dgMarks_RowDetailsVisibilityChanged"    RowDetailsVisibilityMode="Collapsed" Height="391" HorizontalAlignment="Left" Width="965" SelectionChanged="dgMarks_SelectionChanged"  VerticalScrollBarVisibility="Visible" >
            <sdk:DataGrid.Columns>
                <sdk:DataGridTemplateColumn>
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button x:Name="myButton"   
                            Click="ExpandMarks_Click">
     <TextBlock Text="{Binding Level}" TextWrapping="NoWrap"  ></TextBlock>
                                <Image  x:Name="imgMarks"  Stretch="None"/>
                            </Button>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
                <sdk:DataGridTemplateColumn  Header="Name" Visibility="Collapsed">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate >
                            <sdk:Label Content="{Binding Name}"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>

                <sdk:DataGridTemplateColumn  Header="Marks" Width="80">
                    <sdk:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
   <sdk:Label Content="{Binding Marks}"/>
                        </DataTemplate>
                    </sdk:DataGridTemplateColumn.CellTemplate>
                </sdk:DataGridTemplateColumn>
            </sdk:DataGrid.Columns>
 </sdk:DataGrid>

from database i am getting these values

 name   marks   Level
abc     23       0
xyz     67       1
yu     56        0
aa     89        1

here i am binding these values for datagrid.
i have an tricky thing to be done .based on the level i should be binding image
if level value is 1 then bind the image. if level value is 0 then do not bind the image for that row

i know this is how we need to handle but where should i write this code in which events?

Image imgLevel = (Image)templateTrendScore.FindName("imgMarks");

if (level1==1)
{
  imgLevel .Source = new BitmapImage(new Uri("/Images/image1.JPG", UriKind.Relative));
}

any help would be great thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:28:56+00:00Added an answer on May 15, 2026 at 12:28 am

    A value converter is the item you are after, assuming you have more than 0 and 1 for level (else you’d have used a boolean right?)

    Here is the value converter:-

    [ContentProperty("Items")]
    public class IndexToObjectConverter : IValueConverter
    {
        private readonly ObservableCollection<object> myCol = new ObservableCollection<object>();
    
        public ObservableCollection<object> Items { get { return myCol; } }
    
        #region IValueConverter Members
    
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Items[(int)value];
        }
    
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException("This converter only works for one way binding");
        }
    
        #endregion
    }
    

    In the usercontrol resources you would have this:-

    <UserControl.Resources>
        <local:IndexToObjectConverter x:Key="LevelToImage">
            <BitmapImage />
            <BitmapImage UriSource="Test.png" />
        </local:IndexToObjectConverter>
    </UserControl.Resources>
    

    In you can now bind the Source property of the Image control like this:-

    <Image Source="{Binding Level, Converter={StaticResource LevelToImage}}" />
    

    Now as you invent new level numbers you can add elements to the converter.

    BTW, You appear to have both a TextBlock and an Image inside the Button. Button can only hold a single object so you need to wrap these two inside some panel such as Grid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I convert this XAML code into C# code? <Window.Resources> <DataTemplate x:Key=itemtemplate> <TextBlock
I have some issues with using databinding in silverlight 4 xaml pages, this is
I'm experimenting with the Silverlight 4 SDK DataPager. I have some code in my
I may be confused about the purpose behind INotifyPropertyChanged and Silverlight... I have XAML
I have a Xaml file which is used in a project which can be
There's an SDK that lets developers build activities and games for use in Windows
I am trying to create DependencyProperties that have a nice drop down code completion
i have an requirment based on the value 0,1 i am showing the image.
I have a TreeView on my page. It's bound to a collection of clients

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.