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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:39:18+00:00 2026-05-15T12:39:18+00:00

Is it possible to write this out in a slicker/shorter way? all it is

  • 0

Is it possible to write this out in a slicker/shorter way? all it is doing is setting 3 properties and taking too much room IMO..

   <Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource BasicFont}">
        <Setter Property="Foreground">
            <Setter.Value>
                <Binding>
                    <Binding.Converter>
                        <local:ForegroundColorConverter />
                    </Binding.Converter>
                </Binding>
            </Setter.Value>
        </Setter>
        <Setter Property="Background">
            <Setter.Value>
                <Binding>
                    <Binding.Converter>
                        <local:ColorConverter />
                    </Binding.Converter>
                </Binding>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <Binding>
                    <Binding.Converter>
                        <local:ColorConverter />
                    </Binding.Converter>
                </Binding>

            </Setter.Value>
        </Setter>
    </Style>
  • 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-15T12:39:18+00:00Added an answer on May 15, 2026 at 12:39 pm

    Sort of, first you have to define the Converters before the Style:

    <local:ColorConverter x:Key="colorConverter" />
    

    Then you can use them as StaticResources in your style:

    <Setter Property="BorderBrush" Value="{Binding Converter={StaticResource colorConverter}}" />
    

    Full example

    C#:

    using System;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Media;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
            }
        }
    
        // The converter
        public class ColorConverter : IValueConverter
        {
            #region IValueConverter Members
    
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return Brushes.Red;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }
    
    }
    

    XAML:

    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="Window1" Height="300" Width="354">
        <Window.Resources>
            <local:ColorConverter x:Key="colorConverter" />
            <Style TargetType="{x:Type Button}">
                <Setter Property="Background" Value="{Binding Converter={StaticResource colorConverter}}" />
            </Style>
        </Window.Resources>
        <Grid>
            <Button Margin="8" Content="A button" HorizontalAlignment="Center" VerticalAlignment="Center" />
        </Grid>
    </Window>
    

    Btw, now that I think about it, not sure if you simplified your code, but you don’t actually need a converter for that. You can set a SolidColorBrush instead of a Converter (unless you’re doing some code in the converter), something like this:

    <Window.Resources>
        <SolidColorBrush Color="Red" x:Key="redSolidColorBrush" />
        <SolidColorBrush Color="White" x:Key="whiteSolidColorBrush" />
        <Style TargetType="{x:Type Button}">
            <Setter Property="Background" Value="{StaticResource redSolidColorBrush}" />
            <Setter Property="Foreground" Value="{StaticResource whiteSolidColorBrush}" />
        </Style>
    </Window.Resources>
    <Grid>
        <Button Margin="8" Content="A button" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it as all possible to write out an output integer i'm getting with
For instance is it possible to write this if (variable != null) without using
Is it possible to re-write this query to restart numbering when the UName changes
if this possible to write a com control or activex in C# and use
Is it possible to re-write (Apache Mod-Rewrite) a URL from this: http://www.example.com/view.php?t=h5k6 to this
It seems to be possible in Java to write something like this: private enum
Not sure this is possible, but looking to write a script that would return
I'm not even sure if this is possible, but I've exhausted all of my
I'm gonna try and simplify this as much as possible. Lets say i have
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type

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.