Skip to content

Commit

Permalink
BookLib: 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 7fd5724 commit 9edc012
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/ImageResources.xaml"/>
<ResourceDictionary Source="Resources/ConverterResources.xaml"/>
<ResourceDictionary Source="Resources/ControlResources.xaml"/>
<ResourceDictionary Source="Resources/DataResources.xaml"/>
<ResourceDictionary Source="Resources/LayoutResources.xaml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Waf.BookLibrary.Library.Presentation.Converters;

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

public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture)
{
if (value is not Language language) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Waf.BookLibrary.Library.Presentation.Converters;

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

public object? Convert(object? value, Type? targetType, object? parameter, CultureInfo? culture)
{
return Uri.TryCreate(value as string ?? "", UriKind.RelativeOrAbsolute, out Uri? uri) ? uri : DependencyProperty.UnsetValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<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">

<ControlTemplate x:Key="ErrorTemplate">
<Grid>
<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 All @@ -24,7 +25,7 @@
<AdornedElementPlaceholder x:Name="controlWithError" Margin="1"/>
<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 All @@ -47,7 +48,7 @@
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
<Setter Property="AutomationProperties.ItemStatus">
<Setter.Value>
<MultiBinding Converter="{StaticResource ValidationErrorsConverter}">
<MultiBinding Converter="{x:Static waf:ValidationErrorsConverter.Default}">
<Binding Path="(Validation.Errors)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(Validation.Errors).Count" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
Expand All @@ -59,7 +60,7 @@
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource ErrorTemplate}"/>
<Setter Property="AutomationProperties.ItemStatus">
<Setter.Value>
<MultiBinding Converter="{StaticResource ValidationErrorsConverter}">
<MultiBinding Converter="{x:Static waf:ValidationErrorsConverter.Default}">
<Binding Path="(Validation.Errors)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(Validation.Errors).Count" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
Expand All @@ -85,7 +86,7 @@
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource DataGridErrorTemplate}"/>
<Setter Property="AutomationProperties.ItemStatus">
<Setter.Value>
<MultiBinding Converter="{StaticResource ValidationErrorsConverter}">
<MultiBinding Converter="{x:Static waf:ValidationErrorsConverter.Default}">
<Binding Path="(Validation.Errors)" RelativeSource="{RelativeSource Self}"/>
<Binding Path="(Validation.Errors).Count" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
Expand Down

This file was deleted.

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:Waf.BookLibrary.Library.Presentation.Properties"
xmlns:c="clr-namespace:Waf.BookLibrary.Library.Presentation.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:waf="http://waf.codeplex.com/schemas"
Expand Down Expand Up @@ -66,7 +67,7 @@
SelectedItem="{Binding Book.Language}" Height="24" AutomationProperties.AutomationId="LanguageComboBox">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource LanguageToStringConverter}}"/>
<TextBlock Text="{Binding Converter={x:Static c:LanguageToStringConverter.Default}}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
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:Waf.BookLibrary.Library.Presentation.Properties"
xmlns:c="clr-namespace:Waf.BookLibrary.Library.Presentation.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:waf="http://waf.codeplex.com/schemas"
Expand Down Expand Up @@ -40,7 +41,7 @@
<DataGridTextColumn Binding="{Binding Lastname, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
Header="{x:Static p:Resources.Lastname}" Width="*" ElementStyle="{StaticResource TextCellElementStyle}"
EditingElementStyle="{StaticResource TextCellEditingStyle}"/>
<DataGridHyperlinkColumn Binding="{Binding Email, Converter={StaticResource StringToUriConverter},
<DataGridHyperlinkColumn Binding="{Binding Email, Converter={x:Static c:StringToUriConverter.Default},
UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
Header="{x:Static p:Resources.Email}" Width="3*"
EditingElementStyle="{StaticResource TextCellEditingStyle}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="4" Grid.Row="0" Grid.Column="0"/>
</Grid>
</TabItem>
<TabItem Header="{x:Static p:Resources.Reporting}" Visibility="{Binding ShellService.IsReportingEnabled, Converter={StaticResource BoolToVisibilityConverter}}"
<TabItem Header="{x:Static p:Resources.Reporting}" Visibility="{Binding ShellService.IsReportingEnabled, Converter={x:Static waf:BoolToVisibilityConverter.Default}}"
AutomationProperties.AutomationId="ReportingTabItem">
<ContentControl>
<ContentControl.Style>
Expand Down

0 comments on commit 9edc012

Please sign in to comment.