Fix badge view default text "0" (#1959)

This commit is contained in:
Federico Nembrini 2023-04-02 08:18:10 +02:00 коммит произвёл GitHub
Родитель da30dde36b
Коммит 89a363e093
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 93 добавлений и 5 удалений

Просмотреть файл

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.TestCases"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.TestCases.Issue1900Page">
<pages:BasePage.BindingContext>
<vm:Issue1900ViewModel />
</pages:BasePage.BindingContext>
<ContentPage.Content>
<Grid RowDefinitions="*, *, auto"
Padding="12">
<xct:BadgeView Text="{Binding Counter}"
AutoHide="False"
VerticalOptions="Center"
Grid.Row="0">
<Label Text="Badge should be visible and display 0 as text"
Margin="6" />
</xct:BadgeView>
<xct:BadgeView Text="{Binding Counter}"
VerticalOptions="Center"
Grid.Row="1">
<Label Text="Badge should not be visible"
Margin="6" />
</xct:BadgeView>
<Button Text="Increment"
Command="{Binding ClickCommand}"
Grid.Row="2" />
</Grid>
</ContentPage.Content>
</pages:BasePage>

Просмотреть файл

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Issue1900Page : BasePage
{
public Issue1900Page()
{
InitializeComponent();
}
}
}

Просмотреть файл

@ -0,0 +1,29 @@
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.CommunityToolkit.ObjectModel;
namespace Xamarin.CommunityToolkit.Sample.ViewModels.TestCases
{
public class Issue1900ViewModel : BaseViewModel
{
int counter;
public int Counter
{
get => counter;
set => SetProperty(ref counter, value);
}
public ICommand ClickCommand => new AsyncCommand(Click);
public Issue1900ViewModel()
{
}
Task Click()
{
Counter++;
return Task.CompletedTask;
}
}
}

Просмотреть файл

@ -49,7 +49,7 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.TestCases
typeof(SnackBarActionExceptionPage),
"SnackBar Action Exception",
"Exception in SnackBar's action doesn't crash the app."),
new SectionModel(
typeof(Issue1883Page),
"SnackBar iOS issue GitHub #1883",
@ -58,7 +58,12 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.TestCases
new SectionModel(
typeof(DrawingViewInExpanderPage),
"DrawingView in expander",
"DrawingView in Expander Page")
"DrawingView in Expander Page"),
new SectionModel(
typeof(Issue1900Page),
"BadgeView Issue GitHub #1900",
"BadgeView default text")
};
}
}

Просмотреть файл

@ -29,6 +29,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Pages\TestCases\Issue1900.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Pages\TestCases\Popups\PopupModalPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
@ -52,8 +55,6 @@
<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit\Xamarin.CommunityToolkit\Xamarin.CommunityToolkit.csproj" />
<ProjectReference Include="..\..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj" />
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>

Просмотреть файл

@ -266,6 +266,7 @@ namespace Xamarin.CommunityToolkit.UI.Views
protected override void OnControlInitialized(Grid control)
{
BadgeText.Text = Text;
BadgeIndicatorBackground.Content = BadgeText;
BadgeIndicatorContainer.Children.Add(BadgeIndicatorBackground);