-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2716 from cwensley/curtis/wpf-isolate-resource-di…
…ctionaries Wpf: Isolate resource dictionaries by specifying Version and PublicKey
- Loading branch information
Showing
9 changed files
with
136 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ packages/ | |
.store | ||
.DS_Store | ||
*.proj.Backup.tmp | ||
._.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters