Changing the color of the readonly cell

Grids for WPF Forum

Posted 13 years ago by Alex Hazanov
Version: 11.2.0551
Avatar
I was able to change the color of the name of readonly property using:

xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"

<SolidColorBrush x:Key="{x:Static themes:PropertyGridCommonDictionary.ForegroundDisabledBrushKey}" Color="Black" />
However I also need to change the color of the value as well.
I could not find a way to do so.

Alternatively I would like to prevent the property grid from graying out the readonly items.

Thanks in advance.

Comments (7)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Alex,

The Foreground of the cells actually varies and depends on the property editor used. In most cases, it would just be a ComboBox, but could also be a TextBox or any number of other controls. You would have to add implicit Styles for each type of control to set their Foregrounds property appropriately.


Actipro Software Support

Posted 9 years ago by Bruce Lum
Avatar

We have just started using your PropertyGrid control, and also have a similar issue. All cells in a ReadOnly grid are grayed out, but need the Foreground color on the Name and/or Value cells to be changed to a different one. The grid items are all of String type at this time.

How would I achieve this at the grid level, and at the item level. My WPF knowledge is quite limited, so I rely on sample code (both XAML and C#).

(PropertyGrid for WPF, Editors for WPF, v2016.1 build 0630)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Bruce,

Can you provide some more detail on the request?  I don't believe the name cells change color for read-only cells.  And it's up to the property editor template of each value cell to govern how those render for read-only values.

[Modified 9 years ago]


Actipro Software Support

Posted 9 years ago by Bruce Lum
Avatar

I've first tried the following grid-level XAML code, requesting the entire grid to be read-only:

<propgrid:PropertyGrid Name="propGrid"
  Grid.Row="0" Height="Auto"
  HorizontalAlignment="Stretch"
  Margin="10,10,10,0"
  VerticalAlignment="Stretch"
  IsSummaryVisible="False"
  IsReadOnly="True"
  Width="Auto">
</propgrid:PropertyGrid>

with the following C# code for each property grid item:

String itemValue = "...";
 
PropertyGridPropertyItem item = null;
 
item = new PropertyGridPropertyItem();
item.Name = "applicationVersion";
item.DisplayName = "Application version";
item.ValueType = typeof(String);
item.DefaultValue = itemValue;
item.Value = itemValue; 
item.IsReadOnly = false;    // Overrides the name cell's color, but not the value cell (remains read-only)
//item.IsReadOnly = true;     // Both name/value cells remain read-only
propGrid.Items.Add(item);
    ...
  

If the XAML code has IsReadOnly="False", then each item's IsReadOnly property can be adjusted accordingly. However, in both cases, the grey color makes the grid content half legible. I would like to change this grey color for each name/value cells to specific colors. Each property grid item does not have any Color properties. I don't know what the Style property value should be set to.

I don't know if this related question should be in a new post, but is it possible to prevent any editing events from firing for an item, in order to emulate a Read-Only scenario, and thus prevent the greying of the colors?

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

If you didn't want any cells to use the default disabled color, you could just remap the AssetResourceKeys.ControlForegroundDisabledBrushKey Brush to black (or something else) and put that remapped resource in the PropertyGrid.Resources in XAML.  The first post in this thread tells you how to do that, but use the AssetResourceKeys.ControlForegroundDisabledBrushKey key instead.  Depending on the property editors in use, that might make them look full black instead of gray too.

As for changing to specific colors, perhaps you could do the same sort of thing (resource remapping), making new brushes using the AssetResourceKeys.ControlForegroundDisabledBrushKey key and putting them into the PropertyGridPropertyItem.Resources.

Hope that helps!


Actipro Software Support

Posted 9 years ago by Bruce Lum
Avatar

From what you described, I now have the following XAML code, which appears to change all the name and value cells' foreground color to Black for the entire property grid.

<propgrid:PropertyGrid Name="propGrid"
        Grid.Row="0" 
        Height="Auto" Width="Auto"
        Margin="10,10,10,0"
        HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
        IsSummaryVisible="False" IsReadOnly="True">
    <propgrid:PropertyGrid.Resources>
        <SolidColorBrush x:Key="{x:Static themes:AssetResourceKeys.ControlForegroundDisabledBrushKey}"
Color="Black" />
    </propgrid:PropertyGrid.Resources>
</propgrid:PropertyGrid>
 

I have limited XAML knowledge, so I don't understand your suggestion on how to change to specific colors. How would I add another resource mapping, and then utilize it in the C# code?

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Bruce,

You said before you were creating PropertyGridPropertyItems in code.  Perhaps you could try creating a SolidColorBrush in code for each one and putting it in the item's resources like:

item.Resources[AssetResourceKeys.ControlForegroundDisabledBrushKey] = new SolidColorBrush(Colors.Red);


Actipro Software Support

The latest build of this product (v24.1.3) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.