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

[UWP] Fix incorrect Button rendering inside CollectionView ItemTemplate #14598

Merged
merged 5 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue13588"
Title="Issue 13588">
<Grid
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="If Buttons inside CollectionView renders correctly, the test has passed."/>
<CollectionView
Grid.Row="1">
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>mono</x:String>
<x:String>monodroid</x:String>
<x:String>monotouch</x:String>
<x:String>monorail</x:String>
<x:String>monodevelop</x:String>
<x:String>monotone</x:String>
<x:String>monopoly</x:String>
<x:String>monomodal</x:String>
<x:String>mononucleosis</x:String>
</x:Array>
</CollectionView.ItemsSource>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<Label
Margin="10,5,10,0"
FontAttributes="Bold"
VerticalOptions="Center"
HorizontalOptions="StartAndExpand"
Text="{Binding}"
LineBreakMode="WordWrap" >
</Label>
<Label
Margin="10,0,10,0"
Grid.Column="1"
VerticalOptions="Center"
HorizontalOptions="Start"
LineBreakMode="WordWrap"
Text="Status" />
<!-- Button having the display issue-->
<Button
Grid.Column="3"
Text="X"
VerticalOptions="Center"
HorizontalOptions="End">
</Button>
<!-- Button having the display issue-->
<Button
Grid.Column="2"
Text="Retry"
VerticalOptions="Center"
HorizontalOptions="Center">
</Button>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;

#if UITEST
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(UITestCategories.CollectionView)]
#endif
#if APP
[XamlCompilation(XamlCompilationOptions.Compile)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13588, "[Bug] Button inside collectionview not appearing until UWP window is resized #13552", PlatformAffected.UWP)]
public partial class Issue13588 : TestContentPage
{
public Issue13588()
{
#if APP
Title = "Issue 13588";
InitializeComponent();
#endif
}

protected override void Init()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11795.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14528.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14286.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13588.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10101.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13818.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FrameBackgroundIssue.xaml.cs" />
Expand Down Expand Up @@ -2236,6 +2237,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14286.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13588.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue10101.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
7 changes: 7 additions & 0 deletions Xamarin.Forms.Platform.UAP/ButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
_pointerPressedHandler = new PointerEventHandler(OnPointerPressed);
_button.Click += OnButtonClick;
_button.AddHandler(PointerPressedEvent, _pointerPressedHandler, true);
_button.Loading += ButtonOnLoading;
_button.Loaded += ButtonOnLoaded;

SetNativeControl(_button);
Expand Down Expand Up @@ -71,6 +72,11 @@ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
}
}

void ButtonOnLoading(FrameworkElement sender, object args)
{
Element.IsNativeStateConsistent = false;
}

void ButtonOnLoaded(object o, RoutedEventArgs routedEventArgs)
{
WireUpFormsVsm();
Expand Down Expand Up @@ -313,6 +319,7 @@ protected override void Dispose(bool disposing)
{
_button.Click -= OnButtonClick;
_button.RemoveHandler(PointerPressedEvent, _pointerPressedHandler);
_button.Loading -= ButtonOnLoading;
_button.Loaded -= ButtonOnLoaded;

_pointerPressedHandler = null;
Expand Down