Kullanılmayan panelleri (IsVisible
özelliğini kullanarak) gizleyebilirsiniz - bu onları görsel ağacın dışına çeker, ancak bunları bellekten çıkarmaz.
Her sayfa için bir İçerik Görünümü oluşturursanız, bu örnekte olduğu gibi ana kullanıcı arayüzünüzde bunları kolayca kullanabilirsiniz. bireysel panelleri gizleme olsa bile gizli iken hala bellekte kalır:
using System;
using Xamarin.Forms;
namespace FormsSandbox
{
public class MyView : ContentView
{
public static BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(MyView),
String.Empty, BindingMode.Default, null, TextChanged);
public string Text {
get {
return (string)GetValue (TextProperty);
}
set {
SetValue (TextProperty, value);
}
}
private Label _contentLabel;
public MyView()
{
_contentLabel = new Label {
FontSize = 56,
FontAttributes = FontAttributes.Bold,
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center
};
Content = _contentLabel;
}
static void TextChanged (BindableObject bindable, object oldValue, object newValue)
{
var view = (MyView)bindable;
view._contentLabel.Text = (newValue ?? "").ToString();
}
}
}
XamlPage.xaml (ana UI sayfa:
MyView.cs (bu panellerde istediğiniz her şey olabilir)):
<?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:sandbox="clr-namespace:FormsSandbox"
x:Class="FormsSandbox.XamlPage">
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0,20,0,0" Android="0" WinPhone="0"/>
</ContentPage.Padding>
<Grid RowSpacing="0" ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Text="1" Clicked="ButtonClicked" x:Name="Button1" Grid.Column="0" />
<Button Text="2" Clicked="ButtonClicked" x:Name="Button2" Grid.Column="1" />
<Button Text="3" Clicked="ButtonClicked" x:Name="Button3" Grid.Column="2" />
<sandbox:MyView Text="1" x:Name="View1" Grid.Row="1" Grid.ColumnSpan="3" />
<sandbox:MyView Text="2" x:Name="View2" Grid.Row="1" Grid.ColumnSpan="3" />
<sandbox:MyView Text="3" x:Name="View3" Grid.Row="1" Grid.ColumnSpan="3" />
</Grid>
</ContentPage>
XamlPage.xaml.cs:
using System;
using Xamarin.Forms;
namespace FormsSandbox
{
public partial class XamlPage : ContentPage
{
public XamlPage()
{
InitializeComponent();
SelectButton (Button1);
}
void SelectButton(Button button)
{
View view = null;
if (button == Button1)
view = View1;
if (button == Button2)
view = View2;
if (button == Button3)
view = View3;
View1.IsVisible = View1 == view;
View2.IsVisible = View2 == view;
View3.IsVisible = View3 == view;
Button1.TextColor = (Button1 == button) ? Color.Accent.AddLuminosity(0.18) : (Color)Button.TextColorProperty.DefaultValue;
Button2.TextColor = (Button2 == button) ? Color.Accent.AddLuminosity(0.18) : (Color)Button.TextColorProperty.DefaultValue;
Button3.TextColor = (Button3 == button) ? Color.Accent.AddLuminosity(0.18) : (Color)Button.TextColorProperty.DefaultValue;
Button1.BackgroundColor = (Button1 == button) ? Color.Silver.AddLuminosity(0.18) : Color.Silver.AddLuminosity(0.1);
Button2.BackgroundColor = (Button2 == button) ? Color.Silver.AddLuminosity(0.18) : Color.Silver.AddLuminosity(0.1);
Button3.BackgroundColor = (Button3 == button) ? Color.Silver.AddLuminosity(0.18) : Color.Silver.AddLuminosity(0.1);
}
void ButtonClicked (object sender, EventArgs e)
{
SelectButton ((Button)sender);
}
}
}
teşekkür ederim işe yaradı. – Arti
Lütfen [soru] bölümüne bir göz atın (http://stackoverflow.com/questions/36641270/access-controls-from-view-in-content-page). ContentPage – Arti
'daki contentview giriş alanına erişemiyorum, bu soruya da bir göz attım ve yardımcı olması gereken bir cevap ekledim. Sizin için işe yararsa lütfen cevap olarak işaretleyin, böylece başkaları artık takılmadığınız bir sorunu çözmeye çalışmak için zaman harcamayacaktır :). –