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 4257130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:26:57+00:00 2026-05-21T05:26:57+00:00

I want to change the color on a row. So basically. I get a

  • 0

I want to change the color on a row. So basically. I get a from my Web Service with the names of all my admins. And I want to compare that list to the information in my datagridsource. And if they are admins I want their rows to turn red.

void proxy_GetListOfAdminsInGroupCompleted(object sender, gkws.GetListOfAdminsInGroupCompletedEventArgs e)
    {

        TestlistBox1.ItemsSource = e.Result;

        int i = 0;
        foreach (var item in UsersInSelectedGroup[0])
        {
            foreach (var admin in e.Result)
            {
                if (admin.ToString().Equals(item.ToString()))
                {

                    //Code to change the color of the row where "admin.ToString().Equals(item.ToString())"

                }
            }
            i++;
        }
    }

Thanks!

  • 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-21T05:26:57+00:00Added an answer on May 21, 2026 at 5:26 am

    I created a sample CustomClass:

    public class CustomClass
        {
            public string PropertyToBeWatched { get; set; }
        }
    

    Created a list:

    MyList = new ObservableCollection<CustomClass>();
                MyList.Add(new CustomClass() { PropertyToBeWatched = "1"});
                MyList.Add(new CustomClass() { PropertyToBeWatched = "2" });
                MyList.Add(new CustomClass() { PropertyToBeWatched = "2" });
                MyList.Add(new CustomClass() { PropertyToBeWatched = "2" });
    

    Then created the Datagrid:

    <sdk:DataGrid ItemsSource="{Binding MyList}" RowStyle="{StaticResource Style1}">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Binding="{Binding PropertyToBeWatched}" Header="Property1"/>
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
    

    Then the resources:

    xmlns:sdk1="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data" 
                 xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    
    
     <SolidColorBrush x:Key="Red" Color="#FFFF0000" />
            <SolidColorBrush x:Key="Green" Color="#FF00FF00" />    
    
            <Style x:Key="Style1" TargetType="sdk:DataGridRow">
                <Setter Property="IsTabStop" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="sdk:DataGridRow">
                            <Grid Background="{Binding Converter={StaticResource Test}}">
                                <sdk1:DataGridFrozenGrid x:Name="Root">
                                    <sdk1:DataGridFrozenGrid.Resources>
                                        <Storyboard x:Key="DetailsVisibleTransition">
                                            <DoubleAnimation Duration="00:00:0.1" Storyboard.TargetProperty="ContentHeight" Storyboard.TargetName="DetailsPresenter"/>
                                        </Storyboard>
                                    </sdk1:DataGridFrozenGrid.Resources>
                                                <sdk1:DataGridFrozenGrid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </sdk1:DataGridFrozenGrid.ColumnDefinitions>
                                    <sdk1:DataGridFrozenGrid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </sdk1:DataGridFrozenGrid.RowDefinitions>
                                                                                                                                                                                                                        <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="NormalAlternatingRow">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="NormalSelected">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="MouseOverSelected">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="UnfocusedSelected">
                                            <Storyboard>
                                                <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundRectangle"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="UnfocusedEditing"/>
                                        <VisualState x:Name="NormalEditing"/>
                                        <VisualState x:Name="MouseOverUnfocusedEditing"/>
                                        <VisualState x:Name="MouseOverEditing"/>
                                        <VisualState x:Name="MouseOverUnfocusedSelected"/>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="ValidationStates">
                                        <VisualState x:Name="Valid"/>
                                        <VisualState x:Name="Invalid">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="BackgroundRectangle">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                                </ObjectAnimationUsingKeyFrames>
                                                <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="InvalidVisualElement"/>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                    <Rectangle x:Name="BackgroundRectangle" Grid.ColumnSpan="2" Fill="Red" Opacity="0" Grid.RowSpan="2"/>
                                    <Rectangle x:Name="InvalidVisualElement" Grid.ColumnSpan="2" Fill="#FFF7D8DB" Opacity="0" Grid.RowSpan="2"/>
                                    <sdk1:DataGridRowHeader x:Name="RowHeader" sdk1:DataGridFrozenGrid.IsFrozen="True" Grid.RowSpan="3"/>
                                    <sdk1:DataGridCellsPresenter x:Name="CellsPresenter" Grid.Column="1" sdk1:DataGridFrozenGrid.IsFrozen="True"/>
                                    <sdk1:DataGridDetailsPresenter x:Name="DetailsPresenter" Grid.Column="1" Grid.Row="1"/>
                                    <Rectangle x:Name="BottomGridLine" Grid.Column="1" HorizontalAlignment="Stretch" Height="1" Grid.Row="2"/>
                                </sdk1:DataGridFrozenGrid>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    

    and this is for the converter:

    public class RowStyleConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (((CustomClass)value).PropertyToBeWatched == "1")
                    return App.Current.Resources["Red"] as SolidColorBrush;
                else
                    return App.Current.Resources["Green"] as SolidColorBrush;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new System.NotImplementedException();
            }
        }
    

    It basically gets and sets the solidcolorbrush based on the property “PropertyToBeWatched”.

    Hope this helps

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

Sidebar

Related Questions

I want to change the color of text in a specific row of a
I have an onclick on a table row, I want to change the color
When I click on a row of gridview, I want its color to change.
I have a list view with multi columns... Want to change the background color
I want to change the color of a particular row in jQgrid/treeGrid. can anyone
I want to change the background color of the DGV's row based on particular
I want to change the color of selected row and unselected row in uitableview
I am want to change the color of selected row of grid (gwt-ext grid)
What we want to do is change the background color of row in a
I want to change color of row so I create my own cell renderer:

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.