Skip to content

Commit

Permalink
Merge pull request #2716 from cwensley/curtis/wpf-isolate-resource-di…
Browse files Browse the repository at this point in the history
…ctionaries

Wpf: Isolate resource dictionaries by specifying Version and PublicKey
  • Loading branch information
cwensley authored Dec 18, 2024
2 parents 1b5b7f5 + 2489765 commit f559eb4
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 24 deletions.
80 changes: 77 additions & 3 deletions .editorconfig
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@ root = true

# use tabs by default for everything
[*.cs]
indent_style = tab
indent_size = 4
charset=utf-8
csharp_new_line_before_open_brace = all
csharp_indent_braces=false
csharp_indent_labels = no_change
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_space_around_binary_operators = before_and_after

[*.{csproj,vbproj,fsproj,proj,targets,props}]
indent_style = space
Expand All @@ -19,3 +34,62 @@ tab_size = 2
[*.yml]
intent_style = space
indent_size = 2

[*.{cs,vb}]
# Indentation style/size
charset=utf-8
indent_style = tab
tab_width = 4
indent_size = 4

#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ packages/
.store
.DS_Store
*.proj.Backup.tmp
._.*
45 changes: 45 additions & 0 deletions src/Eto.Wpf/AssemblyAbsoluteResourceDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Eto.Wpf
{
public class AssemblyAbsoluteResourceDictionary : sw.ResourceDictionary, ISupportInitialize
{
public string AssemblyName { get; set; }

public string Path { get; set; }

internal static Uri GetAbsolutePackUri(string path, string assemblyName = null)
{
// Support having multiple copies of Eto running, potentially with different version and/or public key
var assembly = assemblyName != null ? Assembly.Load(assemblyName) : typeof(AssemblyAbsoluteResourceDictionary).Assembly;
var name = assembly.GetName();

var version = "v" + name.Version.ToString() + ";";

var publicKey = name.GetPublicKey();
var publicKeyString = publicKey?.Length > 0 ? BitConverter.ToString(publicKey).Replace("-", "") + ";" : null;

return new Uri($"pack://application:,,,/{name.Name};{version}{publicKeyString}component/{path}", UriKind.Absolute);
}

void ISupportInitialize.EndInit()
{
SetupSource();

base.EndInit();
}

private void SetupSource()
{
if (Source != null)
return;
if (string.IsNullOrEmpty(Path))
throw new InvalidOperationException("No Path was specified");

Source = GetAbsolutePackUri(Path, AssemblyName);
}
}
}
6 changes: 3 additions & 3 deletions src/Eto.Wpf/Forms/ApplicationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void ApplyThemes()
throw new InvalidOperationException("Could not load Xceed.Wpf.Toolkit");

// Add themes to our controls
var assemblyName = typeof(ApplicationHandler).Assembly.GetName().Name;
Control.Resources.MergedDictionaries.Add(new sw.ResourceDictionary { Source = new Uri($"pack://application:,,,/{assemblyName};component/themes/generic.xaml", UriKind.RelativeOrAbsolute) });
var uri = AssemblyAbsoluteResourceDictionary.GetAbsolutePackUri("themes/generic.xaml");
Control.Resources.MergedDictionaries.Add(new sw.ResourceDictionary { Source = uri });
}

protected override void Initialize()
Expand Down Expand Up @@ -169,7 +169,7 @@ protected virtual swm.Imaging.BitmapSource GenerateBadge(float scale, string lab
{
var size = Size.Round(new SizeF(14, 14) * scale);
var bmp = new Bitmap(size, PixelFormat.Format32bppRgba);

using (var graphics = new Graphics(bmp))
{
var font = SystemFonts.Bold(6 * scale);
Expand Down
4 changes: 1 addition & 3 deletions src/Eto.Wpf/themes/controls/DataGrid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
xmlns:r="clr-namespace:Eto.Wpf.CustomControls.TreeGridView"
xmlns:efc="clr-namespace:Eto.Wpf.Forms.Controls"
xmlns:e="clr-namespace:Eto.Wpf"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">
xmlns:s="clr-namespace:System;assembly=mscorlib">

<Style TargetType="DataGridRowsPresenter">
<!-- Avoid endless loop in WPF due to the following:
Expand Down
4 changes: 1 addition & 3 deletions src/Eto.Wpf/themes/controls/ToggleButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
xmlns:r="clr-namespace:Eto.Wpf.CustomControls.TreeGridView"
xmlns:efc="clr-namespace:Eto.Wpf.Forms.Controls"
xmlns:e="clr-namespace:Eto.Wpf"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">
xmlns:s="clr-namespace:System;assembly=mscorlib">

<SolidColorBrush x:Key="ToggleButton.Checked.Background" Color="#FFBBDDEE"/>
<SolidColorBrush x:Key="ToggleButton.Checked.Border" Color="#FF255A83"/>
Expand Down
4 changes: 1 addition & 3 deletions src/Eto.Wpf/themes/controls/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
xmlns:efc="clr-namespace:Eto.Wpf.Forms.Controls"
xmlns:e="clr-namespace:Eto.Wpf"
xmlns:ef="clr-namespace:Eto.Wpf.Forms"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">
xmlns:s="clr-namespace:System;assembly=mscorlib">

<Style TargetType="ef:EtoWindowContent">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
Expand Down
4 changes: 1 addition & 3 deletions src/Eto.Wpf/themes/controls/XceedColorDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
xmlns:efc="clr-namespace:Eto.Wpf.Forms.Controls"
xmlns:e="clr-namespace:Eto.Wpf"
xmlns:ef="clr-namespace:Eto.Wpf.Forms"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit">
xmlns:s="clr-namespace:System;assembly=mscorlib">

<Style TargetType="ef:XceedColorDialog">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
Expand Down
12 changes: 6 additions & 6 deletions src/Eto.Wpf/themes/generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
xmlns:s="clr-namespace:System;assembly=mscorlib">

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/controls/DataGrid.xaml" />
<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/controls/SearchTextBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/controls/WatermarkTextBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/controls/Window.xaml" />
<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/controls/XceedColorDialog.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/controls/DataGrid.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/controls/SearchTextBox.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/controls/WatermarkTextBox.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/controls/Window.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/controls/XceedColorDialog.xaml" />

<ResourceDictionary Source="pack://application:,,,/Eto.Wpf;Component/themes/wpftoolkit/ButtonSpinner.xaml" />
<e:AssemblyAbsoluteResourceDictionary Path="themes/wpftoolkit/ButtonSpinner.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style TargetType="{x:Type r:TreeToggleButton}">
Expand Down

0 comments on commit f559eb4

Please sign in to comment.