Search code examples
c#wpfworkflow-foundationapp.xaml

How to override default colors in dll library


I am using Windows workflow foundation rehost library in my application and i am trying to override default colors but it is modifying, i tried below code in my application but it is not working.

CustomColors.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary x:Uid="ResourceDictionary_1" Source="pack://application:,,,/System.Activities.Presentation;component/System/Activities/Presentation/ColorResources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <SolidColorBrush x:Key="WorkflowViewElementCaption" x:Uid="SolidColorBrush_8" Color="#FFE6E6E6" />
        <SolidColorBrush x:Key="DesignerViewBackground" x:Uid="SolidColorBrush_9" Color="#FF232325" />
        <SolidColorBrush x:Key="LinearGradientBrush" x:Uid="SolidColorBrush_10" Color="#FF232325" />
        <SolidColorBrush x:Key="ShellBarBackgroundBrush" x:Uid="SolidColorBrush_11" Color="#FF232325" />
</ResourceDictionary>

and My App.xaml

<Application.Resources>
    
    <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="CustomColors.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

My C# Code

    WorkflowDesigner wfDesigner = new WorkflowDesigner();
 wfDesigner.Load(new ActivityBuilder() { });
    designerview.Child = wfDesigner.View;

I found the default color source code in enter link description here

Is there any way to override the default colors.


Solution

  • i ended up with copying the DefaultColorResources.xaml and modified colors and i am loading this file in App.xaml.cs file.

    var dyn = (ResourceDictionary)Application.LoadComponent(new Uri("DesignerViewColors.xaml", UriKind.RelativeOrAbsolute));
    Type type = typeof(WorkflowDesignerColors);
    FieldInfo? fieldInfo = type.GetField("defaultColors", BindingFlags.NonPublic | BindingFlags.Static);
    fieldInfo?.SetValue(null, dyn);