Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 89a363e

Browse files
Fix badge view default text "0" (#1959)
1 parent da30dde commit 89a363e

File tree

6 files changed

+93
-5
lines changed

6 files changed

+93
-5
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
5+
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.TestCases"
6+
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
7+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.TestCases.Issue1900Page">
8+
<pages:BasePage.BindingContext>
9+
<vm:Issue1900ViewModel />
10+
</pages:BasePage.BindingContext>
11+
<ContentPage.Content>
12+
<Grid RowDefinitions="*, *, auto"
13+
Padding="12">
14+
<xct:BadgeView Text="{Binding Counter}"
15+
AutoHide="False"
16+
VerticalOptions="Center"
17+
Grid.Row="0">
18+
<Label Text="Badge should be visible and display 0 as text"
19+
Margin="6" />
20+
</xct:BadgeView>
21+
<xct:BadgeView Text="{Binding Counter}"
22+
VerticalOptions="Center"
23+
Grid.Row="1">
24+
<Label Text="Badge should not be visible"
25+
Margin="6" />
26+
</xct:BadgeView>
27+
<Button Text="Increment"
28+
Command="{Binding ClickCommand}"
29+
Grid.Row="2" />
30+
</Grid>
31+
</ContentPage.Content>
32+
</pages:BasePage>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
using Xamarin.Forms;
8+
using Xamarin.Forms.Xaml;
9+
10+
namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases
11+
{
12+
[XamlCompilation(XamlCompilationOptions.Compile)]
13+
public partial class Issue1900Page : BasePage
14+
{
15+
public Issue1900Page()
16+
{
17+
InitializeComponent();
18+
}
19+
}
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Threading.Tasks;
2+
using System.Windows.Input;
3+
using Xamarin.CommunityToolkit.ObjectModel;
4+
5+
namespace Xamarin.CommunityToolkit.Sample.ViewModels.TestCases
6+
{
7+
public class Issue1900ViewModel : BaseViewModel
8+
{
9+
int counter;
10+
11+
public int Counter
12+
{
13+
get => counter;
14+
set => SetProperty(ref counter, value);
15+
}
16+
17+
public ICommand ClickCommand => new AsyncCommand(Click);
18+
19+
public Issue1900ViewModel()
20+
{
21+
}
22+
23+
Task Click()
24+
{
25+
Counter++;
26+
return Task.CompletedTask;
27+
}
28+
}
29+
}

samples/XCT.Sample/ViewModels/TestCases/TestCasesGalleryViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
4949
typeof(SnackBarActionExceptionPage),
5050
"SnackBar Action Exception",
5151
"Exception in SnackBar's action doesn't crash the app."),
52-
52+
5353
new SectionModel(
5454
typeof(Issue1883Page),
5555
"SnackBar iOS issue GitHub #1883",
@@ -58,7 +58,12 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
5858
new SectionModel(
5959
typeof(DrawingViewInExpanderPage),
6060
"DrawingView in expander",
61-
"DrawingView in Expander Page")
61+
"DrawingView in Expander Page"),
62+
63+
new SectionModel(
64+
typeof(Issue1900Page),
65+
"BadgeView Issue GitHub #1900",
66+
"BadgeView default text")
6267
};
6368
}
6469
}

samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32+
<EmbeddedResource Update="Pages\TestCases\Issue1900.xaml">
33+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
34+
</EmbeddedResource>
3235
<EmbeddedResource Update="Pages\TestCases\Popups\PopupModalPage.xaml">
3336
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
3437
</EmbeddedResource>
@@ -52,8 +55,6 @@
5255
<ItemGroup>
5356
<ProjectReference Include="..\..\src\CommunityToolkit\Xamarin.CommunityToolkit\Xamarin.CommunityToolkit.csproj" />
5457
<ProjectReference Include="..\..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj" />
55-
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj"
56-
OutputItemType="Analyzer"
57-
ReferenceOutputAssembly="false"/>
58+
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
5859
</ItemGroup>
5960
</Project>

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/BadgeView/BadgeView.shared.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public FontAttributes FontAttributes
266266

267267
protected override void OnControlInitialized(Grid control)
268268
{
269+
BadgeText.Text = Text;
269270
BadgeIndicatorBackground.Content = BadgeText;
270271

271272
BadgeIndicatorContainer.Children.Add(BadgeIndicatorBackground);

0 commit comments

Comments
 (0)