Browse Source

Merge branch 'master' into master

pull/2254/head
Steven Kirk 7 years ago
committed by GitHub
parent
commit
b66b63dc33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      .github/PULL_REQUEST_TEMPLATE.md
  2. 24
      src/Avalonia.Base/Data/Converters/ObjectConverters.cs
  3. 4
      src/Avalonia.Base/Data/Converters/StringConverters.cs
  4. 2
      src/Avalonia.Controls/ContentControl.cs
  5. 9
      src/Avalonia.Themes.Default/CheckBox.xaml
  6. 4
      src/Avalonia.Themes.Default/TextBox.xaml
  7. 6
      tests/Avalonia.Markup.UnitTests/Data/BindingTests_Converters.cs

27
.github/PULL_REQUEST_TEMPLATE.md

@ -1,16 +1,31 @@
This template is not intended to be prescriptive, but to help us review pull requests it would be useful if you included as much of the following information as possible:
## What does the pull request do?
- What does the pull request do?
- What is the current behavior?
- What is the updated/expected behavior with this PR?
- How was the solution implemented (if it's not obvious)?
Give a bit of background on the PR here, together with links to with related issues etc.
Checklist:
## What is the current behavior?
If the PR is a fix, describe the current incorrect behavior, otherwise delete this section.
## What is the updated/expected behavior with this PR?
Describe how to test the PR.
## How was the solution implemented (if it's not obvious)?
Include any information that might be of use to a reviewer here.
## Checklist
- [ ] Added unit tests (if possible)?
- [ ] Added XML documentation to any related classes?
- [ ] Consider submitting a PR to https://github.com/AvaloniaUI/Avaloniaui.net with user documentation
## Breaking changes
List any breaking changes here. When the PR is merged please add an entry to https://github.com/AvaloniaUI/Avalonia/wiki/Breaking-Changes
## Fixed issues
If the pull request fixes issue(s) list them like this:
Fixes #123

24
src/Avalonia.Base/Data/Converters/ObjectConverters.cs

@ -0,0 +1,24 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
namespace Avalonia.Data.Converters
{
/// <summary>
/// Provides a set of useful <see cref="IValueConverter"/>s for working with objects.
/// </summary>
public static class ObjectConverters
{
/// <summary>
/// A value converter that returns true if the input object is a null reference.
/// </summary>
public static readonly IValueConverter IsNull =
new FuncValueConverter<object, bool>(x => x is null);
/// <summary>
/// A value converter that returns true if the input object is not null.
/// </summary>
public static readonly IValueConverter IsNotNull =
new FuncValueConverter<object, bool>(x => !(x is null));
}
}

4
src/Avalonia.Base/Data/Converters/StringConverters.cs

@ -12,13 +12,13 @@ namespace Avalonia.Data.Converters
/// <summary>
/// A value converter that returns true if the input string is null or an empty string.
/// </summary>
public static readonly IValueConverter NullOrEmpty =
public static readonly IValueConverter IsNullOrEmpty =
new FuncValueConverter<string, bool>(string.IsNullOrEmpty);
/// <summary>
/// A value converter that returns true if the input string is not null or empty.
/// </summary>
public static readonly IValueConverter NotNullOrEmpty =
public static readonly IValueConverter IsNotNullOrEmpty =
new FuncValueConverter<string, bool>(x => !string.IsNullOrEmpty(x));
}
}

2
src/Avalonia.Controls/ContentControl.cs

@ -45,8 +45,6 @@ namespace Avalonia.Controls
static ContentControl()
{
ContentControlMixin.Attach<ContentControl>(ContentProperty, x => x.LogicalChildren);
PseudoClass<ContentControl, object>(ContentProperty, x => x != null, ":valid");
PseudoClass<ContentControl, object>(ContentProperty, x => x == null, ":invalid");
}
/// <summary>

9
src/Avalonia.Themes.Default/CheckBox.xaml

@ -1,9 +1,10 @@
<Styles xmlns="https://github.com/avaloniaui">
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style Selector="CheckBox">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
<Setter Property="Padding" Value="4,0,0,0"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="Template">
@ -38,17 +39,15 @@
TextBlock.Foreground="{TemplateBinding Foreground}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="4,0,0,0"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}"
Grid.Column="1"/>
</Grid>
</ControlTemplate>
</Setter>
</Style>
<Style Selector="CheckBox:invalid /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="IsVisible" Value="False"/>
</Style>
<Style Selector="CheckBox:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style>

4
src/Avalonia.Themes.Default/TextBox.xaml

@ -23,7 +23,7 @@
Path="UseFloatingWatermark"/>
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Text"
Converter="{x:Static StringConverters.NotNullOrEmpty}"/>
Converter="{x:Static StringConverters.IsNotNullOrEmpty}"/>
</MultiBinding>
</TextBlock.IsVisible>
</TextBlock>
@ -36,7 +36,7 @@
<TextBlock Name="watermark"
Opacity="0.5"
Text="{TemplateBinding Watermark}"
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.NullOrEmpty}}"/>
IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"/>
<TextPresenter Name="PART_TextPresenter"
Text="{TemplateBinding Text, Mode=TwoWay}"
CaretIndex="{TemplateBinding CaretIndex}"

6
tests/Avalonia.Markup.UnitTests/Data/BindingTests_Converters.cs

@ -22,14 +22,14 @@ namespace Avalonia.Markup.UnitTests.Data
var target = new Binding(nameof(Class1.Foo))
{
Converter = StringConverters.NullOrEmpty,
Converter = StringConverters.IsNullOrEmpty,
};
var expressionObserver = (BindingExpression)target.Initiate(
textBlock,
TextBlock.TextProperty).Observable;
Assert.Same(StringConverters.NullOrEmpty, expressionObserver.Converter);
Assert.Same(StringConverters.IsNullOrEmpty, expressionObserver.Converter);
}
public class When_Binding_To_String
@ -129,7 +129,7 @@ namespace Avalonia.Markup.UnitTests.Data
var target = new Binding(nameof(Class1.Foo))
{
Converter = StringConverters.NotNullOrEmpty,
Converter = StringConverters.IsNotNullOrEmpty,
StringFormat = "Hello {0}",
};

Loading…
Cancel
Save