forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
20 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
<?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="30" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
|
||
<Frame BackgroundColor="Green"> | ||
<Label Grid.Row="0" Text="I am the template." /> | ||
</Frame> | ||
<ContentPresenter Grid.Row="1" /> | ||
</Grid> | ||
</ControlTemplate> | ||
</ContentPage.ControlTemplate> | ||
</ContentPage> |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Xamarin.Forms; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.Xaml; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.None, 7671, "Automate GC checks of picker disposals", PlatformAffected.WPF)] | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
public partial class Issue7671 : ContentPage | ||
{ | ||
public Issue7671() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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,55 @@ | ||
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); | ||
} | ||
} // proc OnElementChanged | ||
|
||
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(); | ||
} | ||
} | ||
} // proc OnElementPropertyChanged | ||
|
||
|
||
void UpdateContent() | ||
private void UpdateContent() | ||
{ | ||
ContentPage page = Element as ContentPage; | ||
if (page != null) | ||
if (_currentView != null) // destroy current view | ||
{ | ||
if (_currentView != null) | ||
{ | ||
_currentView.Cleanup(); // cleanup old view | ||
} | ||
_currentView?.Cleanup(); | ||
_currentView = null; | ||
} | ||
|
||
_currentView = page.Content; | ||
Control.Content = _currentView != null ? Platform.GetOrCreateRenderer(_currentView).GetNativeElement() : null; | ||
// create new view based on the first children, not content | ||
if (Element is IElementController page) | ||
{ | ||
_currentView = page.LogicalChildren.OfType<VisualElement>().FirstOrDefault(); | ||
if (_currentView != null) | ||
Control.Content = Platform.GetOrCreateRenderer(_currentView).GetNativeElement(); | ||
else | ||
Control.Content = null; | ||
} | ||
else | ||
Control.Content = null; | ||
} | ||
} | ||
} |