Skip to content

Commit

Permalink
InfoMan: Reference ValueConverters via Static instead of StaticResource
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Jul 19, 2024
1 parent 9edc012 commit 26d4174
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BookLibrary;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/BookLibrary;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/BookLibrary;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/BookLibrary;Component/Resources/DataResources.xaml"/>
<ResourceDictionary Source="/BookLibrary;Component/Resources/LayoutResources.xaml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ToolBarResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/LayoutResources.xaml"/>
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:ctrl="clr-namespace:Waf.InformationManager.Common.Presentation.Controls;assembly=Waf.InformationManager.Common.Presentation"
xmlns:cc="clr-namespace:Waf.InformationManager.Common.Presentation.Converters;assembly=Waf.InformationManager.Common.Presentation"
xmlns:dd="clr-namespace:Waf.InformationManager.AddressBook.Modules.Presentation.DesignData"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -34,13 +35,13 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Text="{Binding Firstname, ValidatesOnNotifyDataErrors=False, Converter={StaticResource TargetStringEmptyValueConverter}}" Margin="7"/>
<TextBlock Text="{Binding Firstname, ValidatesOnNotifyDataErrors=False, Converter={x:Static cc:TargetStringEmptyValueConverter.Default}}" Margin="7"/>

<TextBlock Text="{Binding Email, ValidatesOnNotifyDataErrors=False, Converter={StaticResource TargetStringEmptyValueConverter}}" Grid.Column="1" Margin="7"/>
<TextBlock Text="{Binding Email, ValidatesOnNotifyDataErrors=False, Converter={x:Static cc:TargetStringEmptyValueConverter.Default}}" Grid.Column="1" Margin="7"/>

<TextBlock Text="{Binding Lastname, ValidatesOnNotifyDataErrors=False, Converter={StaticResource TargetStringEmptyValueConverter}}" Grid.Row="1" Margin="7,0,7,7"/>
<TextBlock Text="{Binding Lastname, ValidatesOnNotifyDataErrors=False, Converter={x:Static cc:TargetStringEmptyValueConverter.Default}}" Grid.Row="1" Margin="7,0,7,7"/>

<TextBlock Text="{Binding Phone, ValidatesOnNotifyDataErrors=False, Converter={StaticResource TargetStringEmptyValueConverter}}" Grid.Column="1" Grid.Row="1" Margin="7,0,7,7"/>
<TextBlock Text="{Binding Phone, ValidatesOnNotifyDataErrors=False, Converter={x:Static cc:TargetStringEmptyValueConverter.Default}}" Grid.Column="1" Grid.Row="1" Margin="7,0,7,7"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ToolBarResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/LayoutResources.xaml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace Waf.InformationManager.Common.Presentation.Converters;
/// <summary>Value converter that returns a special string if the (string) value is null or empty.</summary>
public class TargetStringEmptyValueConverter : IValueConverter
{
/// <summary>Default instance of the TargetStringEmptyValueConverter.</summary>
public static TargetStringEmptyValueConverter Default { get; } = new();

/// <summary>Returns a special string if the (string) value is null or empty. Otherwise it returns value.</summary>
/// <param name="value">The string value to convert.</param>
/// <param name="targetType">The type of the binding target property. This parameter will be ignored.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ToolBarResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/LayoutResources.xaml"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:waf="http://waf.codeplex.com/schemas">

<SolidColorBrush x:Key="HeaderTextBrush" Color="#003399"/>

Expand All @@ -8,7 +9,7 @@
<AdornedElementPlaceholder x:Name="controlWithError"/>
<Border BorderThickness="1" BorderBrush="#FFDB000C" SnapsToDevicePixels="True">
<Border.ToolTip>
<MultiBinding Converter="{StaticResource ValidationErrorsConverter}">
<MultiBinding Converter="{x:Static waf:ValidationErrorsConverter.Default}">
<Binding ElementName="controlWithError" Path="AdornedElement.(Validation.Errors)"/>
<Binding ElementName="controlWithError" Path="AdornedElement.(Validation.Errors).Count"/>
</MultiBinding>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Waf.InformationManager.EmailClient.Modules.Presentation.Converters;

public class StringCollectionToStringConverter : IValueConverter
{
public static StringCollectionToStringConverter Default { get; } = new();

public object Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture) => string.Join("; ", (IEnumerable<string>)value!);

public object ConvertBack(object? value, Type? targetType, object? parameter, CultureInfo? culture) => throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ToolBarResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/LayoutResources.xaml"/>

<ResourceDictionary Source="/Waf.InformationManager.EmailClient.Modules.Presentation;Component/Resources/ConverterResources.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="Waf.InformationManager.EmailClient.Modules.Presentation.Views.EmailListView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.Converters"
xmlns:s="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.Selectors"
xmlns:ctrl="clr-namespace:Waf.InformationManager.Common.Presentation.Controls;assembly=Waf.InformationManager.Common.Presentation"
xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData"
Expand Down Expand Up @@ -42,7 +43,7 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Text="{Binding To, ValidatesOnNotifyDataErrors=False, Converter={StaticResource StringCollectionToStringConverter}}"
<TextBlock Text="{Binding To, ValidatesOnNotifyDataErrors=False, Converter={x:Static c:StringCollectionToStringConverter.Default}}"
Margin="7" TextTrimming="CharacterEllipsis" />

<TextBlock Text="{Binding Sent, ValidatesOnNotifyDataErrors=False, StringFormat=d}" Grid.Column="1" Margin="7"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="Waf.InformationManager.EmailClient.Modules.Presentation.Views.EmailView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.Converters"
xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -65,17 +66,17 @@

<Label Content="To:" Grid.Row="2" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="2" Grid.Column="1">
<TextBlock Text="{Binding To, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis" />
<TextBlock Text="{Binding To, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis" />
</Label>

<Label Content="CC:" Grid.Row="3" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="3" Grid.Column="1">
<TextBlock Text="{Binding CC, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding CC, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis"/>
</Label>

<Label Content="BCC:" Grid.Row="4" Grid.Column="0" Margin="11,0,0,0"/>
<Label Grid.Row="4" Grid.Column="1">
<TextBlock Text="{Binding Bcc, Converter={StaticResource StringCollectionToStringConverter}}" TextTrimming="CharacterEllipsis"/>
<TextBlock Text="{Binding Bcc, Converter={x:Static c:StringCollectionToStringConverter.Default}}" TextTrimming="CharacterEllipsis"/>
</Label>

<Label Content="Sent:" Grid.Row="5" Grid.Column="0" Margin="11,0,0,0"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="Waf.InformationManager.EmailClient.Modules.Presentation.Views.Pop3SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:waf="http://waf.codeplex.com/schemas"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dd="clr-namespace:Waf.InformationManager.EmailClient.Modules.Presentation.DesignData"
Expand Down Expand Up @@ -54,11 +55,11 @@
<Label Grid.Column="0" Grid.Row="10" Content="User name"/>
<TextBox Grid.Column="2" Grid.Row="10" Width="150"
Text="{Binding Model.SmtpUserCredits.UserName, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=true}"
IsEnabled="{Binding UseSameUserCredits, Converter={StaticResource InvertBooleanConverter}}"/>
IsEnabled="{Binding UseSameUserCredits, Converter={x:Static waf:InvertBooleanConverter.Default}}"/>

<Label Grid.Column="0" Grid.Row="12" Content="Password"/>
<PasswordBox x:Name="smtpPassword" Grid.Column="2" Grid.Row="12" LostFocus="SmtpPasswordChanged" Width="150"
IsEnabled="{Binding UseSameUserCredits, Converter={StaticResource InvertBooleanConverter}}"/>
IsEnabled="{Binding UseSameUserCredits, Converter={x:Static waf:InvertBooleanConverter.Default}}"/>

<CheckBox Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="14" Content="Use same user name and password as for my POP3 server" IsChecked="{Binding UseSameUserCredits}"/>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Waf.InformationManager.Infrastructure.Modules.Presentation.Converters;

public class ItemCountToStringConverter : IValueConverter
{
public static ItemCountToStringConverter Default { get; } = new();

public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture)
{
if (value == null) return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ImageResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ControlResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/ToolBarResources.xaml"/>
<ResourceDictionary Source="/Waf.InformationManager.Common.Presentation;Component/Resources/LayoutResources.xaml"/>

<ResourceDictionary Source="/Waf.InformationManager.Infrastructure.Modules.Presentation;Component/Resources/ConverterResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel.Composition;
using System.Globalization;
using System.Waf.Presentation;
using System.Windows;
using System.Windows.Markup;
using Waf.InformationManager.Common.Applications.Services;
Expand All @@ -13,7 +12,5 @@ internal sealed class PresentationService : IPresentationService
public void Initialize()
{
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

ResourceHelper.AddToApplicationResources(typeof(PresentationService).Assembly, "Resources/ConverterResources.xaml");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Window x:Class="Waf.InformationManager.Infrastructure.Modules.Presentation.Views.ShellWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="clr-namespace:Waf.InformationManager.Infrastructure.Modules.Presentation.Converters"
xmlns:vm="clr-namespace:Waf.InformationManager.Infrastructure.Modules.Applications.ViewModels;assembly=Waf.InformationManager.Infrastructure.Modules.Applications"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -46,7 +47,7 @@
<DataTemplate>
<TextBlock>
<Run Text="{Binding Name, Mode=OneWay}"/>
<Run Text="{Binding ItemCount, Mode=OneWay, Converter={StaticResource ItemCountToStringConverter}}" FontWeight="SemiBold"/>
<Run Text="{Binding ItemCount, Mode=OneWay, Converter={x:Static c:ItemCountToStringConverter.Default}}" FontWeight="SemiBold"/>
</TextBlock>
</DataTemplate>
</TreeViewItem.ItemTemplate>
Expand Down

0 comments on commit 26d4174

Please sign in to comment.