Skip to content

Commit

Permalink
WAF WPF Add Bind class which is a culture aware binding implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Jun 10, 2021
1 parent d906422 commit bbb56f5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</configSections>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>

<userSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ private static void InitializeCultures()
CultureInfo.CurrentUICulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(Settings.Default.UICulture);
}

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
// Set XmlLanguage or use {waf:Bind}. The latter one supports also custom culture settings
//FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
// XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
using System.Diagnostics.CodeAnalysis;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "LocalizationSample.Domain.Person.#Birthday")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "LocalizationSample.Domain.Person.#Name")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "~P:LocalizationSample.Domain.Person.Birthday")]
[assembly: SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "~P:LocalizationSample.Domain.Person.Name")]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<Product>Waf Localization Sample</Product>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\System.Waf\System.Waf.Wpf\System.Waf.Wpf.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx" Generator="PublicResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:LocalizationSample.Properties"
xmlns:waf="http://waf.codeplex.com/schemas"
Title="{x:Static p:Resources.WpfLocalizationDemo}" SizeToContent="WidthAndHeight" ResizeMode="CanMinimize">

<Grid Margin="0,0,11,11">
Expand All @@ -19,7 +20,7 @@
<TextBox Text="{Binding Name}" Grid.Column="1" Grid.Row="0" Width="100" Margin="11,11,0,0"/>

<Label Content="{x:Static p:Resources.Birthday}" Grid.Column="0" Grid.Row="1" Margin="11,6,0,0"/>
<TextBox Text="{Binding Birthday, StringFormat=d}" Grid.Column="1" Grid.Row="1" Width="100" Margin="11,7,0,0"/>
<TextBox Text="{waf:Bind Birthday, StringFormat=d}" Grid.Column="1" Grid.Row="1" Width="100" Margin="11,7,0,0"/>

<Button Content="{x:Static p:Resources.Close}" Click="CloseClick" Grid.Column="1" Grid.Row="2" Width="75" HorizontalAlignment="Right" Margin="11,22,0,0"/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public ShellWindow()
InitializeComponent();
}


private void CloseClick(object sender, RoutedEventArgs e)
{
Close();
Expand Down
22 changes: 22 additions & 0 deletions src/System.Waf/System.Waf/System.Waf.Wpf/Presentation/Bind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;
using System.Windows.Data;

namespace System.Waf.Presentation
{
/// <summary>Culture aware binding, which connects the properties of binding target objects (typically, WPF elements) with any data source. It uses the <see cref="CultureInfo.CurrentCulture"/> for converting the values.</summary>
public class Bind : Binding
{
/// <summary>Initializes a new instance of the <see cref="Bind"/> class.</summary>
public Bind() : base()
{
ConverterCulture = CultureInfo.CurrentCulture;
}

/// <summary>Initializes a new instance of the <see cref="Bind"/> class.</summary>
/// <param name="path">The initial <see cref="Binding.Path"/> for the binding.</param>
public Bind(string path) : base(path)
{
ConverterCulture = CultureInfo.CurrentCulture;
}
}
}

0 comments on commit bbb56f5

Please sign in to comment.