Skip to content

Commit

Permalink
New extensions (#13)
Browse files Browse the repository at this point in the history
* padding for TextBlockExtensions

* Update README.md

* Rows and Cols with funcs

* TextWrapping for TextBlockExtensions

* Update README.md

* TextTrimming for TextBlockExtensions

* Update README.md

* Background for TextBlockExtensions

* Update README.md

* MouseBinding for UIElement

* enhanced TextBlockExtensions

* Update README.md

* update version
  • Loading branch information
MihailsKuzmins committed Aug 15, 2019
1 parent c5b970f commit 4246ee1
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 27 deletions.
4 changes: 2 additions & 2 deletions LayoutExtensions.WPF/LayoutExtensions.WPF.csproj.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<package >
<metadata>
<id>LayoutExtensions.WPF</id>
<version>1.0.6</version>
<version>1.0.7</version>
<authors>Mihails Kuzmins</authors>
<owners>Mihails Kuzmins</owners>
<licenseUrl>https://github.com/MihailsKuzmins/LayoutExtensions/blob/master/LICENSE</licenseUrl>
<licenseUrl>https://raw.githubusercontent.com/MihailsKuzmins/LayoutExtensions/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/MihailsKuzmins/LayoutExtensions</projectUrl>
<iconUrl>https://raw.githubusercontent.com/MihailsKuzmins/LayoutExtensions/master/LayoutEx.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
4 changes: 2 additions & 2 deletions LayoutExtensions.WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.6")]
[assembly: AssemblyFileVersion("1.0.0.6")]
[assembly: AssemblyVersion("1.0.0.7")]
[assembly: AssemblyFileVersion("1.0.0.7")]
[assembly: Guid("7699ea86-1fc1-4e66-b3af-35eb87e95750")]

13 changes: 13 additions & 0 deletions LayoutExtensions.WPF/src/Generic/UiElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public static TUiElement MouseBinding<TUiElement>([NotNull] this TUiElement @thi
return @this;
}

public static TUiElement MouseBinding<TUiElement>([NotNull] this TUiElement @this, MouseAction mouseAction, ICommand command)
where TUiElement : UIElement
{
var mouseBinding = new MouseBinding
{
MouseAction = mouseAction,
Command = command
};

@this.InputBindings.Add(mouseBinding);
return @this;
}

public static TUiElement Visible<TUiElement>([NotNull] this TUiElement @this)
where TUiElement : UIElement
{
Expand Down
14 changes: 14 additions & 0 deletions LayoutExtensions.WPF/src/Standard/GridExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using JetBrains.Annotations;
using LayoutExtensions.WPF.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;

namespace LayoutExtensions.WPF
Expand All @@ -18,5 +20,17 @@ public static Grid Cols([NotNull] this Grid @this, IEnumerable<ColumnDefinition>
@this.ColumnDefinitions.AddRange(cols);
return @this;
}

public static Grid Rows([NotNull] this Grid @this, Func<IEnumerable<RowDefinition>> rowsFunc)
{
@this.RowDefinitions.AddRange(rowsFunc?.Invoke() ?? Enumerable.Empty<RowDefinition>());
return @this;
}

public static Grid Cols([NotNull] this Grid @this, Func<IEnumerable<ColumnDefinition>> colsFunc)
{
@this.ColumnDefinitions.AddRange(colsFunc?.Invoke() ?? Enumerable.Empty<ColumnDefinition>());
return @this;
}
}
}
239 changes: 217 additions & 22 deletions LayoutExtensions.WPF/src/Standard/TextBlockExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,37 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using TA = System.Windows.TextAlignment;
using TT = System.Windows.TextTrimming;
using TW = System.Windows.TextWrapping;

namespace LayoutExtensions.WPF
{
public static class TextBlockExtensions
{
public static TextBlock Foreground([NotNull] this TextBlock @this, Brush brush)
public static TextBlock FontWeight([NotNull] this TextBlock @this, FontWeight fontWeight)
{
@this.Foreground = brush;
@this.FontWeight = fontWeight;
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, Color color)
public static TextBlock Bold([NotNull] this TextBlock @this)
{
@this.Foreground = new SolidColorBrush(color);
@this.FontWeight = FontWeights.Bold;
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, byte a, byte r, byte g, byte b)
public static TextBlock FontStyle([NotNull] this TextBlock @this, FontStyle fontStyle)
{
@this.Foreground = new SolidColorBrush(Color.FromArgb(a, r, g, b));
@this.FontStyle = fontStyle;
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, byte r, byte g, byte b)
{
@this.Foreground = new SolidColorBrush(Color.FromRgb(r, g, b));
return @this;
}
public static TextBlock Italic([NotNull] this TextBlock @this) =>
@this.FontStyle(FontStyles.Italic);

public static TextBlock FontSize([NotNull] this TextBlock @this, double fontSize)
{
@this.FontSize = fontSize;
return @this;
}
public static TextBlock Oblique([NotNull] this TextBlock @this) =>
@this.FontStyle(FontStyles.Oblique);

public static TextBlock FontFamily([NotNull] this TextBlock @this, FontFamily fontFamily)
{
Expand All @@ -62,21 +59,219 @@ public static TextBlock FontFamily([NotNull] this TextBlock @this, Fonts font)
return @this;
}

public static TextBlock FontWeight([NotNull] this TextBlock @this, FontWeight fontWeight)
public static TextBlock Text([NotNull] this TextBlock @this, string text)
{
@this.FontWeight = fontWeight;
@this.Text = text;
return @this;
}

public static TextBlock Bold([NotNull] this TextBlock @this)
public static TextBlock FontStretch([NotNull] this TextBlock @this, FontStretch fontStretch)
{
@this.FontWeight = FontWeights.Bold;
@this.FontStretch = fontStretch;
return @this;
}

public static TextBlock Text([NotNull] this TextBlock @this, string text)
public static TextBlock BaselineOffset([NotNull] this TextBlock @this, double baselineOffset)
{
@this.Text = text;
@this.BaselineOffset = baselineOffset;
return @this;
}

public static TextBlock FontSize([NotNull] this TextBlock @this, double fontSize)
{
@this.FontSize = fontSize;
return @this;
}

public static TextBlock TextWrapping([NotNull] this TextBlock @this, TW textWrapping)
{
@this.TextWrapping = textWrapping;
return @this;
}

public static TextBlock WrapWithOverflow([NotNull] this TextBlock @this) =>
@this.TextWrapping(TW.WrapWithOverflow);

public static TextBlock NoWrap([NotNull] this TextBlock @this) =>
@this.TextWrapping(TW.NoWrap);

public static TextBlock Wrap([NotNull] this TextBlock @this) =>
@this.TextWrapping(TW.Wrap);

public static TextBlock Background([NotNull] this TextBlock @this, Brush brush)
{
@this.Background = brush;
return @this;
}

public static TextBlock Background([NotNull] this TextBlock @this, Color color)
{
@this.Background = new SolidColorBrush(color);
return @this;
}

public static TextBlock Background([NotNull] this TextBlock @this, byte a, byte r, byte g, byte b)
{
@this.Background = new SolidColorBrush(Color.FromArgb(a, r, g, b));
return @this;
}

public static TextBlock Background([NotNull] this TextBlock @this, byte r, byte g, byte b)
{
@this.Background = new SolidColorBrush(Color.FromRgb(r, g, b));
return @this;
}

public static TextBlock TextDecorations([NotNull] this TextBlock @this, TextDecorationCollection textDecorations)
{
@this.TextDecorations = textDecorations;
return @this;
}

public static TextBlock TextEffects([NotNull] this TextBlock @this, TextEffectCollection textEffects)
{
@this.TextEffects = textEffects;
return @this;
}

public static TextBlock LineHeight([NotNull] this TextBlock @this, double lineHeight)
{
@this.LineHeight = lineHeight;
return @this;
}

public static TextBlock LineStackingStrategy([NotNull] this TextBlock @this, LineStackingStrategy lineStackingStrategy)
{
@this.LineStackingStrategy = lineStackingStrategy;
return @this;
}

public static TextBlock Padding([NotNull] this TextBlock @this, double uniform)
{
@this.Padding = new Thickness(uniform);
return @this;
}

public static TextBlock Padding([NotNull] this TextBlock @this, double horizontal, double vertical)
{
@this.Padding = new Thickness(horizontal, vertical, horizontal, vertical);
return @this;
}

public static TextBlock Padding([NotNull] this TextBlock @this, double left, double top, double right, double bottom)
{
@this.Padding = new Thickness(left, top, right, bottom);
return @this;
}

public static TextBlock PaddingHorizontal([NotNull] this TextBlock @this, double horizontal)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(horizontal, Padding.Top, horizontal, Padding.Bottom);
return @this;
}

public static TextBlock PaddingVertical([NotNull] this TextBlock @this, double vertical)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(Padding.Left, vertical, Padding.Right, vertical);
return @this;
}

public static TextBlock PaddingLeft([NotNull] this TextBlock @this, double left)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(left, Padding.Top, Padding.Right, Padding.Bottom);
return @this;
}

public static TextBlock PaddingTop([NotNull] this TextBlock @this, double top)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(Padding.Left, top, Padding.Right, Padding.Bottom);
return @this;
}

public static TextBlock PaddingRight([NotNull] this TextBlock @this, double right)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(Padding.Left, Padding.Top, right, Padding.Bottom);
return @this;
}

public static TextBlock PaddingBottom([NotNull] this TextBlock @this, double bottom)
{
var Padding = @this.Padding;

@this.Padding = new Thickness(Padding.Left, Padding.Top, Padding.Right, bottom);
return @this;
}

public static TextBlock TextAlignment([NotNull] this TextBlock @this, TA textAlignment)
{
@this.TextAlignment = textAlignment;
return @this;
}

public static TextBlock TextLeft([NotNull] this TextBlock @this) =>
@this.TextAlignment(TA.Left);

public static TextBlock TextRight([NotNull] this TextBlock @this) =>
@this.TextAlignment(TA.Right);

public static TextBlock TextCenter([NotNull] this TextBlock @this) =>
@this.TextAlignment(TA.Center);

public static TextBlock TextJustify([NotNull] this TextBlock @this) =>
@this.TextAlignment(TA.Justify);

public static TextBlock TextTrimming([NotNull] this TextBlock @this, TT textTrimming)
{
@this.TextTrimming = textTrimming;
return @this;
}

public static TextBlock TextTrimmingNone([NotNull] this TextBlock @this) =>
@this.TextTrimming(TT.None);

public static TextBlock TextTrimmingCharacterEllipsis([NotNull] this TextBlock @this) =>
@this.TextTrimming(TT.CharacterEllipsis);

public static TextBlock TextTrimmingWordEllipsis([NotNull] this TextBlock @this) =>
@this.TextTrimming(TT.WordEllipsis);

public static TextBlock IsHyphenationEnabled([NotNull] this TextBlock @this, bool isHyphenationEnabled)
{
@this.IsHyphenationEnabled = isHyphenationEnabled;
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, Brush brush)
{
@this.Foreground = brush;
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, Color color)
{
@this.Foreground = new SolidColorBrush(color);
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, byte a, byte r, byte g, byte b)
{
@this.Foreground = new SolidColorBrush(Color.FromArgb(a, r, g, b));
return @this;
}

public static TextBlock Foreground([NotNull] this TextBlock @this, byte r, byte g, byte b)
{
@this.Foreground = new SolidColorBrush(Color.FromRgb(r, g, b));
return @this;
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Available extensions:

- Style - Setter;

- TextBlock - Foreground, FontSize, FontFamily, FontWeight, Bold, Text.
- TextBlock - FontWeight, Bold, FontStyle, Italic, Oblique, FontFamily, Text, FontStretch, BaselineOffset, FontSize, TextWrapping, WrapWithOverflow, NoWrap, Wrap, Background, TextDecorations, TextEffects, LineHeight, LineStackingStrategy, Padding, PaddingHorizontal, PaddingVertical, PaddingLeft, PaddingTop, PaddingRight, PaddingBottom, TextAlignment, TextLeft, TextRight, TextCenter, TextJustify, TextTrimming, TextTrimmingNone, TextTrimmingCharacterEllipsis, TextTrimmingWordEllipsis, IsHyphenationEnabled, Foreground;


- String - ToImageSource.

0 comments on commit 4246ee1

Please sign in to comment.