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

  • SEARCH
  • Home
  • 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

I have the following XAML Code: <sdk:DataGrid Margin=58,8,52,18 Name=dataGridTickets> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn x:Name=ticketNoColumn Header=Ticket No.
I have a xaml file with this code: <GridViewColumn x:Name=lvCol3 Header=Quantità Width=120> <GridViewColumn.CellTemplate> <DataTemplate>
I currently have this XAML Code: <ListView x:Name=listFeedSearch Margin=-548.856,95.333,0,7.667 HorizontalAlignment=Left Width=542.5 RenderTransformOrigin=0.5,0.5 ItemsSource={Binding SearchCollection}>
I have this Xaml Code and I want to get the DataGrid dgRemplacement, I
Can anyone help me figure out whats wrong with this piece of xaml code?
My XAML code is like this: <Window xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation' xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml' Title ='Print Preview
I have this code in a xaml file now in a event handler code
In my application I use the ShinyBlue.xaml resource dictionary which has this code for
In XAML I have: <sdk:TreeView x:Name=navigationTreeView Grid.Column=0 Grid.Row=1 SelectedItemChanged=TreeView_SelectedItemChanged> <sdk:TreeView.ItemContainerStyle> <Style TargetType=sdk:TreeViewItem> <Setter Property=IsExpanded
I use this XAML code for the ListView: <ListView> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding={Binding Path=Flag}

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.