Skip to content

Commit

Permalink
(GH-3954) Do not use DynamicResource to get Storyboards inside Triggers
Browse files Browse the repository at this point in the history
Because this is not possible if there is no App or the resources not being added to the App.xaml.
  • Loading branch information
punker76 committed Oct 28, 2020
1 parent 14c4c17 commit cae08e6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void ApplyBindingScopeOverride()
[Export(typeof(StartupTask))]
public void ApplyViewLocatorOverride()
{
var themeManager = this.serviceLocator.GetInstance<IThemeManager>();
Application.Current.Resources.MergedDictionaries.Add(themeManager.GetThemeResources());

var viewLocator = this.serviceLocator.GetInstance<IViewLocator>();
Micro.ViewLocator.GetOrCreateViewType = viewLocator.GetOrCreateViewType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ViewLocator(IThemeManager themeManager)
}

public UIElement GetOrCreateViewType(Type viewType)

{
var cached = IoC.GetAllInstances(viewType).OfType<UIElement>().FirstOrDefault();
if (cached != null)
Expand All @@ -38,13 +39,11 @@ public UIElement GetOrCreateViewType(Type viewType)

var newInstance = (UIElement)Activator.CreateInstance(viewType);

var window = newInstance as Window;
if (window != null)
{
window.Resources.MergedDictionaries.Add(this.themeManager.GetThemeResources());
}

Micro.ViewLocator.InitializeComponent(newInstance);

// alternative way to use the MahApps resources
// (newInstance as Window)?.Resources.MergedDictionaries.Add(themeManager.GetThemeResources());

return newInstance;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/MahApps.Metro/Styles/Controls.ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
<Condition Binding="{Binding Path=(Controls:TextBoxHelper.HasText), RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ShowFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ShowFloatingMessage}" />
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.HideFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.HideFloatingMessage}" />
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>

Expand Down Expand Up @@ -158,19 +158,19 @@
<Condition Property="IsFocused" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterGotFocus}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterGotFocus}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitGotFocus}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitGotFocus}" />
</MultiTrigger.ExitActions>
</MultiTrigger>

<Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterHasText}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterHasText}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitHasText}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitHasText}" />
</Trigger.ExitActions>
</Trigger>

Expand Down Expand Up @@ -485,10 +485,10 @@
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterGotFocus}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterGotFocus}" />
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitGotFocus}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitGotFocus}" />
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>

Expand All @@ -498,10 +498,10 @@
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterHasText}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterHasText}" />
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitHasText}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitHasText}" />
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>

Expand All @@ -513,10 +513,10 @@
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem, Mode=OneWay, Converter={x:Static Converters:IsNullConverter.Instance}}" Value="False" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ShowFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ShowFloatingMessage}" />
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.HideFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.HideFloatingMessage}" />
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>

Expand Down
12 changes: 6 additions & 6 deletions src/MahApps.Metro/Styles/Controls.DatePicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@
<Condition Binding="{Binding Path=(Controls:TextBoxHelper.HasText), RelativeSource={RelativeSource Self}}" Value="True" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ShowFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ShowFloatingMessage}" />
</MultiDataTrigger.EnterActions>
<MultiDataTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.HideFloatingMessage}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.HideFloatingMessage}" />
</MultiDataTrigger.ExitActions>
</MultiDataTrigger>
</ControlTemplate.Triggers>
Expand Down Expand Up @@ -335,10 +335,10 @@
<Condition Property="IsFocused" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterGotFocus.DatePickerTextBox}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterGotFocus.DatePickerTextBox}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitGotFocus.DatePickerTextBox}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitGotFocus.DatePickerTextBox}" />
</MultiTrigger.ExitActions>
</MultiTrigger>

Expand All @@ -348,10 +348,10 @@

<Trigger Property="Controls:TextBoxHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.EnterHasText.DatePickerTextBox}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.EnterHasText.DatePickerTextBox}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{DynamicResource MahApps.Storyboard.ExitHasText.DatePickerTextBox}" />
<BeginStoryboard Storyboard="{StaticResource MahApps.Storyboard.ExitHasText.DatePickerTextBox}" />
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
Expand Down
Loading

0 comments on commit cae08e6

Please sign in to comment.