Skip to content

Commit

Permalink
Completed ResourceManagement
Browse files Browse the repository at this point in the history
- Resolved suggestions
- Included support for every control possible
- Updated Strings.*.resx files
  • Loading branch information
ShankarBUS committed Jan 5, 2021
1 parent 88e771a commit 5e5eb5b
Show file tree
Hide file tree
Showing 259 changed files with 34,105 additions and 3,933 deletions.
20 changes: 20 additions & 0 deletions ModernWpf.Controls/Common/ResourceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ModernWpf.Controls
{
internal static class ResourceHelper
{
/// <summary>
/// This method must be called from every control/class's constructor (<see langword="static"/> or default)
/// present in the <strong>ModernWpf.Controls</strong> assembly
/// that makes use of the <see cref="ResourceAccessor.GetLocalizedStringResource(string)"/> method.
/// </summary>
/// <remarks>
/// This method ensures that the <see cref="ResourceAccessor"/> is aware of this (<strong>ModernWpf.Controls</strong>) assembly.
/// We use this method instead of using the <see cref="System.Reflection.Assembly.GetCallingAssembly"/> method
/// because it is unreliable and may cause instabilities in the end application.
/// </remarks>
public static void Initialize()
{
ResourceAccessor.modernWpfControlsAssembly ??= typeof(ResourceHelper).Assembly;
}
}
}
26 changes: 14 additions & 12 deletions ModernWpf.Controls/NavigationView/NavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using ModernWpf.Input;
using ModernWpf.Media.Animation;
using static CppWinRTHelpers;
using static ModernWpf.ResourceAccessor;

namespace ModernWpf.Controls
{
Expand Down Expand Up @@ -213,6 +214,7 @@ void UnhookEventsAndClearFields(bool isFromDestructor = false)

static NavigationView()
{
ResourceHelper.Initialize();
DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationView), new FrameworkPropertyMetadata(typeof(NavigationView)));
}

Expand Down Expand Up @@ -546,8 +548,8 @@ public override void OnApplyTemplate()
if (GetTemplateChild(c_topNavOverflowButton) is Button topNavOverflowButton)
{
m_topNavOverflowButton = topNavOverflowButton;
AutomationProperties.SetName(topNavOverflowButton, ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationOverflowButtonName));
topNavOverflowButton.Content = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationOverflowButtonText);
AutomationProperties.SetName(topNavOverflowButton, ResourceAccessor.GetLocalizedStringResource(SR_NavigationOverflowButtonName));
topNavOverflowButton.Content = ResourceAccessor.GetLocalizedStringResource(SR_NavigationOverflowButtonText);
// TODO: WPF - Header Animation
/*
auto visual = winrt::ElementCompositionPreview::GetElementVisual(topNavOverflowButton);
Expand All @@ -558,7 +560,7 @@ public override void OnApplyTemplate()
if (toolTip is null)
{
var tooltip = new ToolTip();
tooltip.Content = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationOverflowButtonToolTip);
tooltip.Content = ResourceAccessor.GetLocalizedStringResource(SR_NavigationOverflowButtonToolTip);
ToolTipService.SetToolTip(topNavOverflowButton, tooltip);
}

Expand Down Expand Up @@ -650,7 +652,7 @@ public override void OnApplyTemplate()
m_paneSearchButton = button;
button.Click += OnPaneSearchButtonClick;

var searchButtonName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationViewSearchButtonName);
var searchButtonName = ResourceAccessor.GetLocalizedStringResource(SR_NavigationViewSearchButtonName);
AutomationProperties.SetName(button, searchButtonName);
var toolTip = new ToolTip();
toolTip.Content = searchButtonName;
Expand All @@ -662,7 +664,7 @@ public override void OnApplyTemplate()
m_backButton = backButton;
backButton.Click += OnBackButtonClicked;

string navigationName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationBackButtonName);
string navigationName = ResourceAccessor.GetLocalizedStringResource(SR_NavigationBackButtonName);
AutomationProperties.SetName(backButton, navigationName);

WindowChrome.SetIsHitTestVisibleInChrome(backButton, true);
Expand All @@ -684,7 +686,7 @@ public override void OnApplyTemplate()

if (GetTemplateChild(c_navViewBackButtonToolTip) is ToolTip backButtonToolTip)
{
string navigationBackButtonToolTip = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationBackButtonToolTip);
string navigationBackButtonToolTip = ResourceAccessor.GetLocalizedStringResource(SR_NavigationBackButtonToolTip);
backButtonToolTip.Content = navigationBackButtonToolTip;
}

Expand All @@ -693,15 +695,15 @@ public override void OnApplyTemplate()
m_closeButton = closeButton;
closeButton.Click += OnPaneToggleButtonClick;

string navigationName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationCloseButtonName);
string navigationName = ResourceAccessor.GetLocalizedStringResource(SR_NavigationCloseButtonName);
AutomationProperties.SetName(closeButton, navigationName);

WindowChrome.SetIsHitTestVisibleInChrome(closeButton, true);
}

if (GetTemplateChild(c_navViewCloseButtonToolTip) is ToolTip closeButtonToolTip)
{
string navigationCloseButtonToolTip = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationButtonOpenName);
string navigationCloseButtonToolTip = ResourceAccessor.GetLocalizedStringResource(SR_NavigationButtonOpenName);
closeButtonToolTip.Content = navigationCloseButtonToolTip;
}

Expand Down Expand Up @@ -1380,7 +1382,7 @@ void CreateAndHookEventsToSettings()
settingsItem.Icon = settingsIcon;

// Do localization for settings item label and Automation Name
var localizedSettingsName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_SettingsButtonName);
var localizedSettingsName = ResourceAccessor.GetLocalizedStringResource(SR_SettingsButtonName);
AutomationProperties.SetName(settingsItem, localizedSettingsName);
settingsItem.Tag = localizedSettingsName;
UpdateSettingsItemToolTip();
Expand Down Expand Up @@ -1952,11 +1954,11 @@ void SetPaneToggleButtonAutomationName()
string navigationName;
if (IsPaneOpen)
{
navigationName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationButtonOpenName);
navigationName = ResourceAccessor.GetLocalizedStringResource(SR_NavigationButtonOpenName);
}
else
{
navigationName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationButtonClosedName);
navigationName = ResourceAccessor.GetLocalizedStringResource(SR_NavigationButtonClosedName);
}

if (m_paneToggleButton is { } paneToggleButton)
Expand All @@ -1978,7 +1980,7 @@ void UpdateSettingsItemToolTip()
}
else
{
var localizedSettingsName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_SettingsButtonName);
var localizedSettingsName = ResourceAccessor.GetLocalizedStringResource(SR_SettingsButtonName);
var toolTip = new ToolTip();
toolTip.Content = localizedSettingsName;
ToolTipService.SetToolTip(settingsItem, toolTip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using ModernWpf.Controls;
using static ModernWpf.ResourceAccessor;

namespace ModernWpf.Automation.Peers
{
Expand All @@ -18,6 +19,7 @@ public class NavigationViewItemAutomationPeer :
public NavigationViewItemAutomationPeer(NavigationViewItem owner) :
base(owner)
{
ResourceHelper.Initialize();
}

protected override string GetNameCore()
Expand All @@ -38,7 +40,7 @@ protected override string GetNameCore()
// NB: It'll be up to the app to determine the automation label for
// when they're using a PlaceholderValue vs. Value.

returnHString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NavigationViewItemDefaultControlName);
returnHString = ResourceAccessor.GetLocalizedStringResource(SR_NavigationViewItemDefaultControlName);
}

return returnHString;
Expand Down
6 changes: 4 additions & 2 deletions ModernWpf.Controls/NumberBox/NumberBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using ModernWpf.Automation.Peers;
using static ModernWpf.ResourceAccessor;

namespace ModernWpf.Controls
{
Expand Down Expand Up @@ -47,6 +48,7 @@ public partial class NumberBox : Control

static NumberBox()
{
ResourceHelper.Initialize();
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumberBox), new FrameworkPropertyMetadata(typeof(NumberBox)));
}

Expand Down Expand Up @@ -89,8 +91,8 @@ public override void OnApplyTemplate()
{
base.OnApplyTemplate();

var spinDownName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NumberBoxDownSpinButtonName);
var spinUpName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_NumberBoxUpSpinButtonName);
var spinDownName = ResourceAccessor.GetLocalizedStringResource(SR_NumberBoxDownSpinButtonName);
var spinUpName = ResourceAccessor.GetLocalizedStringResource(SR_NumberBoxUpSpinButtonName);

if (GetTemplateChild(c_numberBoxDownButtonName) is RepeatButton spinDown)
{
Expand Down
28 changes: 15 additions & 13 deletions ModernWpf.Controls/PersonPicture/PersonPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
using System.Windows.Media;
using System.Windows.Shapes;
using ModernWpf.Automation.Peers;
using static ModernWpf.ResourceAccessor;

namespace ModernWpf.Controls
{
public partial class PersonPicture : Control
{
static PersonPicture()
{
ResourceHelper.Initialize();
DefaultStyleKeyProperty.OverrideMetadata(typeof(PersonPicture), new FrameworkPropertyMetadata(typeof(PersonPicture)));
}

Expand Down Expand Up @@ -268,7 +270,7 @@ void UpdateAutomationName()
// if none exist, it defaults to "Person"
if (IsGroup)
{
contactName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_GroupName);
contactName = ResourceAccessor.GetLocalizedStringResource(SR_GroupName);
}
else if (!string.IsNullOrEmpty(DisplayName))
{
Expand All @@ -280,7 +282,7 @@ void UpdateAutomationName()
}
else
{
contactName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_PersonName);
contactName = ResourceAccessor.GetLocalizedStringResource(SR_PersonName);
}

// BadgeInformation portion of the AutomationName is set to 'n items' if there is a BadgeNumber,
Expand All @@ -291,7 +293,7 @@ void UpdateAutomationName()
if (!string.IsNullOrEmpty(BadgeText))
{
automationName = string.Format(
ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemTextOverride),
ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemTextOverride),
contactName,
BadgeNumber,
BadgeText);
Expand All @@ -309,14 +311,14 @@ void UpdateAutomationName()
if (!string.IsNullOrEmpty(BadgeText))
{
automationName = string.Format(
ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeIconTextOverride),
ResourceAccessor.GetLocalizedStringResource(SR_BadgeIconTextOverride),
contactName,
BadgeText);
}
else
{
automationName = string.Format(
ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeIcon),
ResourceAccessor.GetLocalizedStringResource(SR_BadgeIcon),
contactName);
}
}
Expand All @@ -336,35 +338,35 @@ string GetLocalizedPluralBadgeItemStringResource(int numericValue)

if (numericValue == 1) // Singular
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemSingular);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemSingular);
}
else if (numericValue == 2) // 2
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural7);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural7);
}
else if (numericValue == 3 || numericValue == 4) // 3,4
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural2);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural2);
}
else if (numericValue >= 5 && numericValue <= 10) // 5-10
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural5);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural5);
}
else if (numericValue >= 11 && numericValue <= 19) // 11-19
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural6);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural6);
}
else if (valueMod10 == 1) // 21, 31, 41, etc.
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural1);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural1);
}
else if (valueMod10 >= 2 && valueMod10 <= 4) // 22-24, 32-34, 42-44, etc.
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural3);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural3);
}
else // Everything else... 0, 20, 25-30, 35-40, etc.
{
value = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_BadgeItemPlural4);
value = ResourceAccessor.GetLocalizedStringResource(SR_BadgeItemPlural4);
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

using System.Windows.Automation.Peers;
using ModernWpf.Controls;
using static ModernWpf.ResourceAccessor;

namespace ModernWpf.Automation.Peers
{
public class ProgressRingAutomationPeer : FrameworkElementAutomationPeer
{
public ProgressRingAutomationPeer(ProgressRing owner) : base(owner)
{
ResourceHelper.Initialize();
}

protected override string GetClassNameCore()
Expand All @@ -25,7 +27,7 @@ protected override string GetNameCore()
{
if (progressRing.IsActive)
{
return Strings.ProgressRingIndeterminateStatus + name;
return ResourceAccessor.GetLocalizedStringResource(SR_ProgressRingIndeterminateStatus) + name;
}
}
return name;
Expand All @@ -35,5 +37,10 @@ protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.ProgressBar;
}

protected override string GetLocalizedControlTypeCore()
{
return ResourceAccessor.GetLocalizedStringResource(SR_ProgressRingName);
}
}
}
Loading

0 comments on commit 5e5eb5b

Please sign in to comment.