Skip to content

A Swiss Army knife for developers.

Fixed a bug where the navigation view items would not fit the Compact mode.

Etienne Baudoux121c21834bc0
diff --git a/src/dev/impl/DevTools.Common/DevTools.Common.csproj b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
index d73df37f6..d7650ffec 100644
--- a/src/dev/impl/DevTools.Common/DevTools.Common.csproj
+++ b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
@@ -87,6 +87,7 @@
<Compile Include="UI\Controls\ExpandableSettingHeaderControl.xaml.cs">
<DependentUpon>ExpandableSettingHeaderControl.xaml</DependentUpon>
</Compile>
+ <Compile Include="UI\Converters\EnumToThicknessConverter.cs" />
<Compile Include="UI\Converters\BooleanToVisibilityConverter.cs" />
<Compile Include="UI\Converters\DoubleToGridLengthConverter.cs" />
<Compile Include="UI\Converters\InvertedBooleanConverter.cs" />
@@ -143,6 +144,9 @@
<ItemGroup>
<PRIResource Include="Strings\en\JsonFormatter.resw" />
</ItemGroup>
+ <ItemGroup>
+ <PRIResource Include="Strings\en\Common.resw" />
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/src/dev/impl/DevTools.Common/LanguageManager.cs b/src/dev/impl/DevTools.Common/LanguageManager.cs
index 1fb300655..0ec877f59 100644
--- a/src/dev/impl/DevTools.Common/LanguageManager.cs
+++ b/src/dev/impl/DevTools.Common/LanguageManager.cs
@@ -22,6 +22,7 @@ namespace DevTools.Common
private static LanguageManager _languageManager;
private readonly Base64EncoderDecoderStrings _base64encoderdecoder = new Base64EncoderDecoderStrings();
+ private readonly CommonStrings _common = new CommonStrings();
private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();
private readonly MainPageStrings _mainpage = new MainPageStrings();
private readonly SettingsStrings _settings = new SettingsStrings();
@@ -41,6 +42,11 @@ namespace DevTools.Common
/// </summary>
public Base64EncoderDecoderStrings Base64EncoderDecoder => _base64encoderdecoder;
+ /// <summary>
+ /// Gets the <see cref="CommonStrings"/>.
+ /// </summary>
+ public CommonStrings Common => _common;
+
/// <summary>
/// Gets the <see cref="JsonFormatterStrings"/>.
/// </summary>
@@ -97,6 +103,21 @@ namespace DevTools.Common
public string DisplayName => _resources.GetString("DisplayName");
}
+ public class CommonStrings : ObservableObject
+ {
+ private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/Common");
+
+ /// <summary>
+ /// Gets the resource ToggleSwitchOff.
+ /// </summary>
+ public string ToggleSwitchOff => _resources.GetString("ToggleSwitchOff");
+
+ /// <summary>
+ /// Gets the resource ToggleSwitchOn.
+ /// </summary>
+ public string ToggleSwitchOn => _resources.GetString("ToggleSwitchOn");
+ }
+
public class JsonFormatterStrings : ObservableObject
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/JsonFormatter");
@@ -136,9 +157,69 @@ namespace DevTools.Common
{
private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/Settings");
+ /// <summary>
+ /// Gets the resource About.
+ /// </summary>
+ public string About => _resources.GetString("About");
+
+ /// <summary>
+ /// Gets the resource AppTheme.
+ /// </summary>
+ public string AppTheme => _resources.GetString("AppTheme");
+
+ /// <summary>
+ /// Gets the resource AppThemeDescription.
+ /// </summary>
+ public string AppThemeDescription => _resources.GetString("AppThemeDescription");
+
+ /// <summary>
+ /// Gets the resource Behaviors.
+ /// </summary>
+ public string Behaviors => _resources.GetString("Behaviors");
+
+ /// <summary>
+ /// Gets the resource Dark.
+ /// </summary>
+ public string Dark => _resources.GetString("Dark");
+
/// <summary>
/// Gets the resource DisplayName.
/// </summary>
public string DisplayName => _resources.GetString("DisplayName");
+
+ /// <summary>
+ /// Gets the resource Font.
+ /// </summary>
+ public string Font => _resources.GetString("Font");
+
+ /// <summary>
+ /// Gets the resource Light.
+ /// </summary>
+ public string Light => _resources.GetString("Light");
+
+ /// <summary>
+ /// Gets the resource SmartDetection.
+ /// </summary>
+ public string SmartDetection => _resources.GetString("SmartDetection");
+
+ /// <summary>
+ /// Gets the resource SmartDetectionDescription.
+ /// </summary>
+ public string SmartDetectionDescription => _resources.GetString("SmartDetectionDescription");
+
+ /// <summary>
+ /// Gets the resource TextEditor.
+ /// </summary>
+ public string TextEditor => _resources.GetString("TextEditor");
+
+ /// <summary>
+ /// Gets the resource UsefulLinks.
+ /// </summary>
+ public string UsefulLinks => _resources.GetString("UsefulLinks");
+
+ /// <summary>
+ /// Gets the resource UseSystemSettings.
+ /// </summary>
+ public string UseSystemSettings => _resources.GetString("UseSystemSettings");
}
}
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Common/Strings/en/Common.resw b/src/dev/impl/DevTools.Common/Strings/en/Common.resw
new file mode 100644
index 000000000..7087289f4
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/Strings/en/Common.resw
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="ToggleSwitchOff" xml:space="preserve">
+ <value>Off</value>
+ </data>
+ <data name="ToggleSwitchOn" xml:space="preserve">
+ <value>On</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Common/Themes/Custom.xaml b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
index f31dc2552..b197cfc8c 100644
--- a/src/dev/impl/DevTools.Common/Themes/Custom.xaml
+++ b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
@@ -24,6 +24,8 @@
<Setter Property="MinWidth" Value="0" />
<Setter Property="FocusVisualMargin" Value="-7,-3,-7,-3" />
<Setter Property="CornerRadius" Value="{StaticResource ControlCornerRadius}" />
+ <Setter Property="OnContent" Value="{Binding Instance.Common.ToggleSwitchOn, Source={StaticResource LanguageManager}}"/>
+ <Setter Property="OffContent" Value="{Binding Instance.Common.ToggleSwitchOff, Source={StaticResource LanguageManager}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleSwitch">
@@ -605,4 +607,10 @@
</Setter.Value>
</Setter>
</Style>
+
+ <Style x:Key="SubTitleTextBlock" TargetType="TextBlock">
+ <Setter Property="FontSize" Value="14" />
+ <Setter Property="FontWeight" Value="Medium" />
+ <Setter Property="Margin" Value="0,12,0,0" />
+ </Style>
</ResourceDictionary>
diff --git a/src/dev/impl/DevTools.Common/Themes/Generic.xaml b/src/dev/impl/DevTools.Common/Themes/Generic.xaml
index 33dc40dc4..e7954f5c5 100644
--- a/src/dev/impl/DevTools.Common/Themes/Generic.xaml
+++ b/src/dev/impl/DevTools.Common/Themes/Generic.xaml
@@ -1,7 +1,9 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:controls="using:DevTools.Common.UI.Controls">
+ xmlns:controls="using:DevTools.Common.UI.Controls"
+ xmlns:common="using:DevTools.Common">
+ <common:LanguageManager x:Key="LanguageManager"/>
<Style TargetType="controls:CustomPathIcon">
<Setter Property="Stretch" Value="Uniform"/>
@@ -13,4 +15,9 @@
<Style TargetType="FontIcon">
<Setter Property="FontFamily" Value="{StaticResource FluentSystemIcons}"/>
</Style>
+
+ <Style TargetType="ToggleSwitch">
+ <Setter Property="OnContent" Value="{Binding Instance.Common.ToggleSwitchOn, Source={StaticResource LanguageManager}}"/>
+ <Setter Property="OffContent" Value="{Binding Instance.Common.ToggleSwitchOff, Source={StaticResource LanguageManager}}"/>
+ </Style>
</ResourceDictionary>
diff --git a/src/dev/impl/DevTools.Common/UI/Converters/EnumToThicknessConverter.cs b/src/dev/impl/DevTools.Common/UI/Converters/EnumToThicknessConverter.cs
new file mode 100644
index 000000000..7f411575f
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Converters/EnumToThicknessConverter.cs
@@ -0,0 +1,51 @@
+#nullable enable
+
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Data;
+
+namespace DevTools.Common.UI.Converters
+{
+ /// <summary>
+ /// Convert a <see cref="Enum"/> to a <see cref="Thickness"/> value.
+ /// </summary>
+ public sealed class EnumToThicknessConverter : IValueConverter
+ {
+ /// <summary>
+ /// Gets or sets the thickness to apply when the input is has the expected enum.
+ /// </summary>
+ public Thickness ThicknessOnEnumDetected { get; set; }
+
+ /// <summary>
+ /// Gets or sets the thickness to apply when the input is doesn't have the expected enum.
+ /// </summary>
+ public Thickness ThicknessOnEnumNotDetected { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ if (value == null || parameter == null || !(value is Enum))
+ {
+ return ThicknessOnEnumNotDetected;
+ }
+
+ var currentState = value.ToString();
+ var stateStrings = parameter.ToString();
+
+ string[] stateStringsSplitted = stateStrings.Split(',');
+ for (int i = 0; i < stateStringsSplitted.Length; i++)
+ {
+ if (string.Equals(currentState, stateStringsSplitted[i].Trim(), StringComparison.Ordinal))
+ {
+ return ThicknessOnEnumDetected;
+ }
+ }
+
+ return ThicknessOnEnumNotDetected;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
index 8381e59b4..ac8f122e6 100644
--- a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
@@ -38,6 +38,7 @@ namespace DevTools.Impl.ViewModels
private readonly Task _firstUpdateMenuTask;
private MatchedToolProviderViewData? _selectedItem;
+ private NavigationViewDisplayMode _navigationViewDisplayMode;
private string? _searchQuery;
private bool _isInCompactOverlayMode;
private bool _allowSelectAutomaticallyRecommendedTool = true;
@@ -112,6 +113,20 @@ namespace DevTools.Impl.ViewModels
}
}
+ /// <summary>
+ /// Gets or sets in what mode the navigation view is displayed.
+ /// </summary>
+ public NavigationViewDisplayMode NavigationViewDisplayMode // Important to keep this property Public to bind it to ChangePropertyAction in the XAML.
+ {
+ get => _navigationViewDisplayMode;
+ set
+ {
+ _thread.ThrowIfNotOnUIThread();
+ _navigationViewDisplayMode = value;
+ OnPropertyChanged();
+ }
+ }
+
[ImportingConstructor]
public MainPageViewModel(
IThread thread,
diff --git a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
index b43608938..b0220072f 100644
--- a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
+++ b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
@@ -11,18 +11,17 @@
xmlns:icore="using:Microsoft.Xaml.Interactions.Core"
xmlns:ex="using:DevTools.Common.UI.Extensions"
xmlns:converters="using:DevTools.Common.UI.Converters"
- xmlns:common="using:DevTools.Common"
xmlns:controls="using:DevTools.Common.UI.Controls"
xmlns:viewmanagement="using:Windows.UI.ViewManagement"
mc:Ignorable="d"
NavigationCacheMode="Enabled"
muxc:BackdropMaterial.ApplyToRootOrPageBackground="True">
<Page.Resources>
- <common:LanguageManager x:Key="LanguageManager"/>
<converters:DoubleToGridLengthConverter x:Key="DoubleToGridLengthConverter"/>
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:BooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" IsInverted="True"/>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter"/>
+ <converters:EnumToThicknessConverter x:Key="NavigationViewItemMarginConverter" ThicknessOnEnumDetected="0" ThicknessOnEnumNotDetected="12,0,12,0"/>
<!--This top margin is the height of the custom TitleBar-->
<Thickness x:Key="NavigationViewContentMargin">0,48,0,0</Thickness>
@@ -133,6 +132,7 @@
<!-- Navigation view -->
<muxc:NavigationView
+ x:Name="NavigationView"
IsTitleBarAutoPaddingEnabled="False"
IsSettingsVisible="False"
IsBackButtonVisible="Collapsed"
@@ -147,12 +147,17 @@
MenuItemsSource="{x:Bind ViewModel.ToolsMenuItems}"
FooterMenuItemsSource="{x:Bind ViewModel.FooterMenuItems}"
SelectedItem="{x:Bind ViewModel.SelectedMenuItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
+ <i:Interaction.Behaviors>
+ <icore:EventTriggerBehavior EventName="DisplayModeChanged">
+ <icore:ChangePropertyAction TargetObject="{x:Bind ViewModel}" PropertyName="NavigationViewDisplayMode" Value="{x:Bind NavigationView.DisplayMode, Mode=OneWay}"/>
+ </icore:EventTriggerBehavior>
+ </i:Interaction.Behaviors>
<muxc:NavigationView.MenuItemTemplate>
<DataTemplate x:DataType="models:MatchedToolProviderViewData">
<muxc:NavigationViewItem
Icon="{x:Bind Icon.Result, Mode=OneWay}"
- Margin="12,0,12,0">
+ Margin="{Binding NavigationViewDisplayMode, ConverterParameter='Compact', Converter={StaticResource NavigationViewItemMarginConverter}}">
<muxc:NavigationViewItem.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem
diff --git a/src/tests/DevTools.Tests/UI/ConvertersTests.cs b/src/tests/DevTools.Tests/UI/ConvertersTests.cs
index 5bd18c2a2..b83096ad4 100644
--- a/src/tests/DevTools.Tests/UI/ConvertersTests.cs
+++ b/src/tests/DevTools.Tests/UI/ConvertersTests.cs
@@ -3,6 +3,7 @@
using DevTools.Common.UI.Converters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
namespace DevTools.Tests.UI
{
@@ -48,5 +49,20 @@ namespace DevTools.Tests.UI
Assert.IsFalse((bool)converter.Convert(string.Empty, typeof(bool), null, null));
Assert.IsTrue((bool)converter.Convert("foo", typeof(bool), null, null));
}
+
+ [TestMethod]
+ public void EnumToThicknessConverterTest()
+ {
+ var converter = new EnumToThicknessConverter();
+ converter.ThicknessOnEnumDetected = new Thickness(10);
+ converter.ThicknessOnEnumNotDetected = new Thickness(0);
+
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(null, null, "foo", null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, null, null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert("foo", null, "foo", null));
+
+ Assert.AreEqual(converter.ThicknessOnEnumDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Compact", null));
+ Assert.AreEqual(converter.ThicknessOnEnumNotDetected, converter.Convert(AppBarClosedDisplayMode.Compact, null, "Test", null));
+ }
}
}