Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed resource markup extension to attached behaviors. Fixes #2
- Loading branch information
1 parent
afe486c
commit b319fe4
Showing
39 changed files
with
2,659 additions
and
134 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
Igniter.Tests.Live/DirectoryResourcesBehaviorTestWindow.xaml
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,16 @@ | ||
<Window x:Class="Igniter.Tests.Live.DirectoryResourcesBehaviorTestWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ign="http://schemas.northhorizon.net/igniter" | ||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" | ||
Title="DirectoryResourcesBehaviorTestWindow" Height="300" Width="300"> | ||
<i:Interaction.Behaviors> | ||
<ign:DirectoryResourcesBehavior Directory="DirectoryResourcesBehaviorTestFolder" IsSubdirectoriesIncluded="False"/> | ||
</i:Interaction.Behaviors> | ||
<UniformGrid Columns="1"> | ||
<Border Background="{StaticResource Color1}"/> | ||
<Border Background="{StaticResource Color2}"/> | ||
<Border Background="{DynamicResource Color1}"/> | ||
<Border Background="{DynamicResource Color2}"/> | ||
</UniformGrid> | ||
</Window> |
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
13 changes: 0 additions & 13 deletions
13
Igniter.Tests.Live/FolderResourceDictionaryTestWindow.xaml
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<ResourceDictionary.MergedDictionaries> | ||
<ResourceDictionary Source="/Igniter.Tests.Live;component/TestSharedResources.xaml"/> | ||
</ResourceDictionary.MergedDictionaries> | ||
<!-- Resource dictionary entries should be defined here. --> | ||
</ResourceDictionary> |
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,23 @@ | ||
<Window x:Class="Igniter.Tests.Live.SharedResourceBehaviorTestWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ign="http://schemas.northhorizon.net/igniter" | ||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" | ||
Title="SharedResourceBehaviorTestWindow" Height="300" Width="300"> | ||
<UniformGrid Columns="1"> | ||
<UniformGrid Columns="1"> | ||
<i:Interaction.Behaviors> | ||
<ign:SharedResourceBehavior Source="testsharedresources.xaml"/> | ||
</i:Interaction.Behaviors> | ||
<Border Background="{StaticResource Brush1}"/> | ||
<Border Background="{DynamicResource Brush1}"/> | ||
</UniformGrid> | ||
<UniformGrid Columns="1"> | ||
<i:Interaction.Behaviors> | ||
<ign:SharedResourceBehavior Source="TESTSHAREDRESOURCES.XAML"/> | ||
</i:Interaction.Behaviors> | ||
<Border Background="{StaticResource Brush2}"/> | ||
<Border Background="{DynamicResource Brush2}"/> | ||
</UniformGrid> | ||
</UniformGrid> | ||
</Window> |
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
20 changes: 0 additions & 20 deletions
20
Igniter.Tests.Live/SharedResourceDictionaryTestWindow.xaml
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Interactivity; | ||
using System.Windows.Markup; | ||
|
||
namespace Igniter.Behaviors | ||
{ | ||
public abstract class ResourceBehvior : Behavior<FrameworkElement>, IUriContext | ||
{ | ||
private ResourceDictionary _attachedResources; | ||
|
||
Uri IUriContext.BaseUri { get; set; } | ||
|
||
protected abstract ResourceDictionary ProvideAttachedResources(IUriContext uriContext); | ||
|
||
protected override void OnAttached() | ||
{ | ||
base.OnAttached(); | ||
|
||
_attachedResources = ProvideAttachedResources(this); | ||
AssociatedObject.Resources.MergedDictionaries.Add(_attachedResources); | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
AssociatedObject.Resources.MergedDictionaries.Remove(_attachedResources); | ||
_attachedResources = null; | ||
|
||
base.OnDetaching(); | ||
} | ||
} | ||
} |
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,27 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Markup; | ||
using Igniter.Core; | ||
|
||
namespace Igniter.Behaviors | ||
{ | ||
/// <summary> | ||
/// Provides cached resource dictionaries to avoid loading the same resources multiple times. | ||
/// </summary> | ||
public sealed class SharedResourceBehavior : ResourceBehvior | ||
{ | ||
/// <summary> | ||
/// Gets or sets the URI of the dictionary to load. | ||
/// </summary> | ||
public Uri Source { get; set; } | ||
|
||
protected override ResourceDictionary ProvideAttachedResources(IUriContext uriContext) | ||
{ | ||
if (Source == null) return null; | ||
|
||
var uri = this.ResolvePartUri(Source); | ||
|
||
return ResourceCache.GetOrCreate(uri); | ||
} | ||
} | ||
} |
Oops, something went wrong.