This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] ContentPage.ControlTemplate gets not rendered in Wpf (#7671) #7728
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage 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.Issue7671"> | ||
<ContentPage.Content> | ||
<StackLayout> | ||
<Label Text="Welcome to Xamarin.Forms!" | ||
VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="CenterAndExpand" /> | ||
</StackLayout> | ||
</ContentPage.Content> | ||
<ContentPage.ControlTemplate> | ||
<ControlTemplate> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="60" /> | ||
<RowDefinition /> | ||
<RowDefinition Height="60" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Frame Grid.Row="0" BackgroundColor="Green"> | ||
<Label Text="I am the template." /> | ||
</Frame> | ||
<ContentPresenter Grid.Row="1" /> | ||
<Frame Grid.Row="2" BackgroundColor="Red"> | ||
<Label Text="I am the template." /> | ||
</Frame> | ||
</Grid> | ||
</ControlTemplate> | ||
</ContentPage.ControlTemplate> | ||
</ContentPage> |
21 changes: 21 additions & 0 deletions
21
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7671.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.None, 7671, "Check ControlTemplate rendering", PlatformAffected.WPF)] | ||
#if APP | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
#endif | ||
public partial class Issue7671 : ContentPage | ||
{ | ||
public Issue7671() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
namespace Xamarin.Forms.Platform.WPF.Controls | ||
using System; | ||
using System.Windows; | ||
using WpfSize = System.Windows.Size; | ||
|
||
namespace Xamarin.Forms.Platform.WPF.Controls | ||
{ | ||
public class FormsContentPage : FormsPage | ||
{ | ||
public FormsContentPage() | ||
{ | ||
this.DefaultStyleKey = typeof(FormsContentPage); | ||
} | ||
|
||
static FormsContentPage() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(FormsContentPage), new FrameworkPropertyMetadata(typeof(FormsContentPage))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Xamarin.Forms.Platform.WPF.Controls; | ||
|
||
namespace Xamarin.Forms.Platform.WPF | ||
{ | ||
public class PageRenderer : VisualPageRenderer<Page, FormsContentPage> | ||
{ | ||
VisualElement _currentView; | ||
VisualElement _currentView = null; | ||
|
||
protected override void OnElementChanged(ElementChangedEventArgs<Page> e) | ||
{ | ||
if (e.NewElement != null) | ||
{ | ||
if (Control == null) // construct and SetNativeControl and suscribe control event | ||
{ | ||
if (Control == null) | ||
SetNativeControl(new FormsContentPage()); | ||
} | ||
|
||
// Update control property | ||
UpdateContent(); | ||
} | ||
|
||
base.OnElementChanged(e); | ||
} | ||
|
||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
base.OnElementPropertyChanged(sender, e); | ||
|
||
if (e.PropertyName == ContentPage.ContentProperty.PropertyName) | ||
|
||
if (e.PropertyName == ContentPage.ContentProperty.PropertyName | ||
|| e.PropertyName == TemplatedPage.ControlTemplateProperty.PropertyName) | ||
{ | ||
UpdateContent(); | ||
} | ||
} | ||
|
||
void UpdateContent() | ||
{ | ||
ContentPage page = Element as ContentPage; | ||
if (page != null) | ||
if (Element is ContentPage page) | ||
{ | ||
if (_currentView != null) | ||
if (_currentView != null) // destroy current view | ||
{ | ||
_currentView.Cleanup(); // cleanup old view | ||
_currentView?.Cleanup(); | ||
_currentView = null; | ||
} | ||
|
||
_currentView = page.Content; | ||
_currentView = page.LogicalChildren.OfType<VisualElement>().FirstOrDefault() ?? page.Content; | ||
Control.Content = _currentView != null ? Platform.GetOrCreateRenderer(_currentView).GetNativeElement() : null; | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using the FrameworkPropertyMetadata?