我的 xaml on pcl 项目中有一个图像列表 当我在 samsumg galaxy s5 设备上测试我的应用程序时 我这样做:我进入列表的页面,然后我按下操作栏上的后退按钮......我做了很多次......然后,它发生了:
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.Platform+DefaultRenderer from native handle 0x20e0001d (key_handle 0x42433c30).
或
Unable to activate instance of type Xamarin.Forms.Platform.Android.LabelRenderer from native
更新
我添加了这个脚本:
using System;
using Android.Runtime;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Xamarin.Forms.Label), typeof(LabelRenderer))]
namespace neoFly_Montana.Droid
{
/// <summary>
/// This renderer was added to resolve a bug that crashed the application in known case
/// Bug 36285 - Android App (Always) Crashes After Navigating Away From Page With A ScrollView In HeaderTemplate of ListView
/// <seealso cref="https://bugzilla.xamarin.com/show_bug.cgi?id=36285"/>
/// and
/// Bug 32462 - Crash after a page disappeared if a ScrollView is in the HeaderTemplate property of a ListView
/// <seealso cref="https://bugzilla.xamarin.com/show_bug.cgi?id=32462"/>
/// </summary>
public class LabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
public LabelRenderer()
{ }
public LabelRenderer(IntPtr javaReference, JniHandleOwnership transfer): base()
{ }
}
}
错误依旧
------------------------------------更新
然后,我改变了,现在我的代码是:
using System;
using Android.Runtime;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using neoFly_Montana.Droid;
using Android.Content;
[assembly: ExportRenderer(typeof(Xamarin.Forms.Label),
typeof(NeoFly_MontanaLabelRenderer))]
namespace neoFly_Montana.Droid
{
public class NeoFly_MontanaLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
public NeoFly_MontanaLabelRenderer(Context context) : base(context)
{
}
}
}
然后,我可以经常看到这个错误。
System.NotSupportedException: Unable to activate instance of type neoFly_Montana.Droid.NeoFly_MontanaLabelRenderer from native handle
当我按下顶部栏上的后退按钮时正在运行的页面发生错误 XAML (PCL):
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="neoFly_Montana.Views.ProdutosView"
xmlns:local="clr-namespace:neoFly_Montana.LayoutScripts"
xmlns:interface="clr-namespace:neoFly_Montana.Interface"
xmlns:effect="clr-namespace:neoFly_Montana.Effects"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
BackgroundImage="prodBackground.jpg"
x:Name="ParentHost">
<ContentPage.Content>
<Grid HorizontalOptions="FillAndExpand" RowSpacing="0" VerticalOptions="StartAndExpand">
<Grid.RowDefinitions>
<RowDefinition Height="9.5*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<!-- Lista de produtos -->
<ListView Grid.Row="0" Grid.Column="0" ItemSelected="ListView_ItemSelected" CachingStrategy="RecycleElement" BackgroundColor="Transparent" x:Name="listview_produtos" Margin="10,0,10,0" SeparatorVisibility="None" HasUnevenRows="True" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<ListView.Header>
<!-- Observação -->
<StackLayout>
<StackLayout x:Name="prod_stack_obser" IsVisible="False" Orientation="Horizontal" Spacing="0" HorizontalOptions="FillAndExpand">
<Label x:Name="label_observ" HorizontalTextAlignment="Start" VerticalOptions="Center" FontSize="Small" TextColor="White" Style="{StaticResource labelsfont}" Margin="20,10,0,10" />
<ffimageloading:CachedImage x:Name="lapis" Source="lapis.png" IsVisible="False" HorizontalOptions="EndAndExpand"/>
</StackLayout>
<BoxView HeightRequest="20"/>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="20,0,20,20">
<ffimageloading:CachedImage Source="texturaCateg.png" BackgroundColor="{Binding FundoColor, Source={x:Reference ParentHost}}" Grid.Row="0" Grid.Column="0" Aspect="Fill" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
<StackLayout Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" x:Name="produtos_stack_color" Spacing="10">
<StackLayout Spacing="0" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">
<StackLayout Orientation="Horizontal" Padding="10,10,10,0" VerticalOptions="Center" HorizontalOptions="FillAndExpand">
<ffimageloading:CachedImage FadeAnimationForCachedImages="True" DownsampleUseDipUnits="True" DownsampleHeight="60" HeightRequest="83" WidthRequest="130" Source="{Binding imagem}" Aspect="Fill" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" >
<!--<ffimageloading:CachedImage.CacheKeyFactory>
<interface:CustomCacheKeyFactory/>
</ffimageloading:CachedImage.CacheKeyFactory>-->
</ffimageloading:CachedImage>
<!--HeightRequest="83" WidthRequest="100"-->
<!--DownsampleHeight="83"-->
<!--<StackLayout Orientation="Horizontal" VerticalOptions="Center" HorizontalOptions="EndAndExpand">
<Label Style="{StaticResource labelsfont}" Text="R$" VerticalOptions="CenterAndExpand" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" FontSize="Medium"/>
<Label Style="{StaticResource labelsfont}" Text="{Binding valor}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" FontAttributes="Bold" VerticalOptions="Start" FontSize="30"/>
</StackLayout>-->
</StackLayout>
<!--nome-->
<Label Text="{Binding nome}" Margin="0,10,0,10" Style="{StaticResource labelsfont}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="CenterAndExpand"/>
</StackLayout>
<Grid VerticalOptions="FillAndExpand">
<BoxView Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="WhiteSmoke" Opacity="0.2"/>
<Label Grid.Row="0" Grid.Column="0" Margin="10,10,10,10" HorizontalTextAlignment="Center" Text="{Binding observacao}" Opacity="1" FontSize="Small" Style="{StaticResource labelsfont}" TextColor="{Binding TextColor, Source={x:Reference ParentHost}}" HorizontalOptions="Center" />
</Grid>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout>
<Grid x:Name="prod_rl_fundo" >
<Grid.Margin>
<OnPlatform x:TypeArguments="Thickness"
iOS="20,0,20,0"
Android="20,10,20,10"/>
</Grid.Margin>
<ffimageloading:CachedImage x:Name="prod_acomp_img" Source="texturaCateg.png" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" Aspect="Fill" VerticalOptions="FillAndExpand"></ffimageloading:CachedImage>
<!--Acompanhamentos-->
<StackLayout x:Name="stack_acompanhamentos" Spacing="0" Grid.Row="0" Grid.Column="0">
<Grid x:Name="prod_acompanhamentos_title" HorizontalOptions="FillAndExpand">
<BoxView Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="WhiteSmoke" Opacity="0.2"/>
<Label x:Name="produtos_acomp_title" Text="+ Dois Acompanhamentos" Grid.Row="0" Grid.Column="0" Style="{StaticResource labelsfont}" Margin="20,20,20,20" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Center" />
</Grid>
</StackLayout>
</Grid>
<BoxView HeightRequest="50"></BoxView>
</StackLayout>
</ListView.Footer>
</ListView>
<!--Rodapé Grid-->
<Grid Grid.Row="1" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<ffimageloading:CachedImage Source="rodape.png"
HorizontalOptions="FillAndExpand"
Aspect="AspectFill"
VerticalOptions="FillAndExpand"
Grid.Row="0"/>
<!--Escrito Rodapé-->
<StackLayout StyleId="rodapemenu" Orientation="Horizontal"
Margin ="5,5,5,5" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Grid.Row="0">
<Label
FontSize="Micro"
Text="Você está em:"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="White"/>
<StackLayout.Effects>
<effect:SafeAreaPaddingEffect />
</StackLayout.Effects>
<Label FontSize="Micro"
Text="loja"
x:Name="prod_lbl_lojaprox"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="{StaticResource laranjacolor}"
LineBreakMode="TailTruncation"
FontAttributes="Bold" />
</StackLayout>
</Grid>
</Grid>
</ContentPage.Content>
那个的 C#
using FFImageLoading;
using FFImageLoading.Forms;
using neoFly_Montana.Api;
using neoFly_Montana.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace neoFly_Montana.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ProdutosView : ContentPage
{
List<Produtos> lstProdutos = new List<Produtos>();
Categorias categEscolhida;
public Color FundoColor { get { return fundoColor; } }
public Color TextColor { get { return textColor; } }
Color fundoColor;
Color textColor;
string lojaProx;
string codLoja;
public ProdutosView(string codLoja, Object categEscolhida, object produtos, string lojaProx)
{
this.codLoja = codLoja;
this.categEscolhida = new Categorias();
this.categEscolhida = (Categorias)categEscolhida;
lstProdutos = (List<Produtos>)produtos;
fundoColor = Color.FromHex(this.categEscolhida.corFundo);
textColor = Color.FromHex(this.categEscolhida.corTexto);
this.Title = this.categEscolhida.nome;
//TrataImagens();
InitializeComponent();
if (lojaProx != null)
{
this.lojaProx = lojaProx;
prod_lbl_lojaprox.Text = lojaProx;
}
PopulaListView();
//if (Device.OS == TargetPlatform.iOS)
//{
// this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
//}
}
void TrataImagens()
{
foreach (var item in lstProdutos)
{
if (item.imagem != null && item.imagem.Trim() != "")
{
int initIndex = item.imagem.IndexOf(',');
string u = item.imagem.Substring(initIndex+1);
try
{
var bytes= Convert.FromBase64String(item.imagem);
item.imagem = System.Text.Encoding.Unicode.GetString(bytes, 0, bytes.Length);
// item.imagem = Encoding.UTF8.GetString(bytes);
}
catch (Exception e)
{
var ss = e.Message;
}
}
}
}
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var list = (ListView)sender;
list.SelectedItem = null;
}
void PopulaListView()
{
int row = 0;
int column = 0;
Grid grid_acompanhamentos = new Grid
{
// BackgroundColor = Color.Red,
RowSpacing = 0,
Padding = new Thickness(0, 0, 0, 0),
HorizontalOptions = LayoutOptions.CenterAndExpand,
Margin = new Thickness(10, 10, 10, 10),
ColumnSpacing = 0,
};
//CachedImage prod_acomp_img = new CachedImage
//{
// Source = "texturaCateg.png",
// Aspect = Aspect.Fill,
// BackgroundColor = Color.FromHex(this.categEscolhida.corFundo)
//};
//produtos
listview_produtos.ItemsSource = lstProdutos;
//observação
if (categEscolhida.observacao != null && categEscolhida.observacao.Trim() != "") {
label_observ.Text = categEscolhida.observacao;
prod_stack_obser.IsVisible = true;
lapis.IsVisible = true;
}
//acompanhamentos
if (categEscolhida.acompanhamentos == null || categEscolhida.acompanhamentos.Count() == 0)
{
stack_acompanhamentos.IsVisible = false;
}
else
{
//prod_acompanhamentos_title.BackgroundColor = fundoColor;
prod_acomp_img.BackgroundColor = fundoColor;
produtos_acomp_title.TextColor = textColor;
foreach (var item in categEscolhida.acompanhamentos)
{
StackLayout stack = new StackLayout();
stack.Margin = new Thickness (0,10,0,10);
stack.HorizontalOptions = LayoutOptions.StartAndExpand;
//stack.BackgroundColor = Color.Orange;
stack.Spacing = 0;
stack.Children.Add(new Label { Text = item.nome, HorizontalTextAlignment = TextAlignment.Start, TextColor = textColor, HorizontalOptions=LayoutOptions.Start, FontAttributes = FontAttributes.Bold, FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) });
if (item.observacao != null)
stack.Children.Add(new Label { Text = item.observacao, HorizontalTextAlignment = TextAlignment.Start, HorizontalOptions = LayoutOptions.Start, TextColor = textColor, FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) });
else
stack.Children.Add(new Label { Text = " ", TextColor = textColor, HorizontalTextAlignment = TextAlignment.Start, HorizontalOptions = LayoutOptions.Start, FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) });
grid_acompanhamentos.Children.Add(stack, column, row);
if (column == 0)
{
column = 1;
}
else
{
column = 0;
row++;
}
}
stack_acompanhamentos.Children.Add(grid_acompanhamentos);
//produtos_rl_acompanhamentos.Children.Add(grid_acompanhamentos,
// Constraint.RelativeToParent((parent) =>
// {
// return (parent.Width / 2) - (grid_acompanhamentos.Width / 2);
// }),
// Constraint.RelativeToParent((parent) =>
// {
// return (parent.Height / 2) - (grid_acompanhamentos.Height / 2);
// })
//);
//produtos_rl_acompanhamentos.Children.Add(prod_acomp_img, Constraint.RelativeToParent((parent) => {
// return parent.X;
//}), Constraint.RelativeToParent((parent) => {
// return parent.Y;
//}), Constraint.RelativeToParent((parent) => {
// return parent.Width;
//}), Constraint.RelativeToView(grid_acompanhamentos, (parent, sibling) => {
// var teste = sibling.Height;
// return teste;
//}));
//UpdateConstraintsBasedOnWidth(produtos_rl_acompanhamentos, grid_acompanhamentos);
// produtos_rl_acompanhamentos.RaiseChild(grid_acompanhamentos);
}
}
public static void UpdateConstraintsBasedOnWidth(Xamarin.Forms.RelativeLayout layout, Xamarin.Forms.View view)
{
view.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
{
if (e.PropertyName == "Width") { layout.ForceLayout(); }
};
view.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
{
if (e.PropertyName == "Height") { layout.ForceLayout(); }
};
}
}
}
The Previous page 发生错误时应该回到的上一页 XAML (PCL)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="neoFly_Montana.Views.CategoriasView"
xmlns:effect="clr-namespace:neoFly_Montana.Effects"
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
Title="Cardápio">
<ContentPage.Content>
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<ffimageloading:CachedImage Source="familiaBackground.jpg" Grid.Row="0" Grid.Column="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Aspect="Fill"/>
<!--Categ grid-->
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="9.5*"/>
<RowDefinition Height="0.5*"/>
</Grid.RowDefinitions>
<Grid x:Name="gridtextura" RowSpacing="20" BindingContext="{Binding nome}" Padding="10, 10, 10, 10" Margin="10,10,10,10"/>
<!--Rodapé Grid-->
<Grid Grid.Row="1" Grid.Column="0" VerticalOptions="FillAndExpand">
<Image Source="rodape.png"
Aspect="Fill"
Grid.Row="0"
VerticalOptions="FillAndExpand"/>
<!--Escrito Rodapé-->
<StackLayout StyleId="rodapemenu" Orientation="Horizontal" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Grid.Row="0" Grid.Column="0">
<StackLayout.Effects>
<effect:SafeAreaPaddingEffect />
</StackLayout.Effects>
<Label
FontSize="Micro"
Text="Você está em:"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="White"/>
<Label FontSize="Micro"
Text="loja"
x:Name="categorias_lbl_ljproxima"
Style="{StaticResource labelsfont}"
VerticalOptions="CenterAndExpand"
TextColor="{StaticResource laranjacolor}"
LineBreakMode="TailTruncation"
FontAttributes="Bold" />
</StackLayout>
</Grid>
</Grid>
</Grid>
</ContentPage.Content>
代码隐藏
using FFImageLoading.Forms;
using neoFly_Montana.Api;
using neoFly_Montana.Model;
using neoFly_Montana.PopUp;
using Rg.Plugins.Popup.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace neoFly_Montana.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CategoriasView : ContentPage
{
ActivityIndicator indicator;
string codigoLoja;
List<Categorias> lstCategorias;
List<Produtos> lstProdutos = new List<Produtos>();
List<Acompanhamento> lstAcompanhamentos;
Categorias categoriaEscolhida;
string observacao;
string codCategoria;
string lojaProx;
LoadingPopUp loading;
public CategoriasView(string codigoLoja, string lojaProx, object lstCategorias)
{
this.codigoLoja = codigoLoja;
this.lojaProx = lojaProx;
//this.codigoLoja = "162";
this.lstCategorias = (List<Categorias>)lstCategorias;
InitializeComponent();
categorias_lbl_ljproxima.Text = lojaProx;
CriaTela();
}
void CriaLoading()
{
LoadingPopUp loading = new LoadingPopUp("Carregando...", Color.Brown);
PopupNavigation.PushAsync(loading, false);
}
private void CriaTela()
{
int row = 0;
int column = 0;
gridtextura.RowSpacing = 5;
gridtextura.ColumnSpacing = 15;
lstCategorias = lstCategorias.OrderBy(o => o.nome).ToList();
foreach (var item in lstCategorias)
{
Grid GridContent = new Grid
{
RowSpacing = 0,
Margin = new Thickness(0, 5, 0, 0),
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
}
};
var textura = new CachedImage();
textura.Source = "texturaCateg";
textura.HorizontalOptions = LayoutOptions.FillAndExpand;
textura.VerticalOptions = LayoutOptions.FillAndExpand;
textura.Aspect = Aspect.Fill;
GridContent.BindingContext = item;
Grid boxColorView = new Grid
{
RowSpacing = 0,
//InputTransparent = true,
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(2, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(8, GridUnitType.Star) }
}
};
boxColorView.Children.Add(new StackLayout { BackgroundColor = Color.FromHex(item.corFundo), VerticalOptions = LayoutOptions.FillAndExpand }, 0, 1);
boxColorView.Children.Add(textura, 0, 1);
// boxColorView.Children.Add(new BoxView { VerticalOptions = LayoutOptions.FillAndExpand }, 0, 0);
gridtextura.Children.Add(boxColorView, column, row);
gridtextura.Children.Add(GridContent, column, row);
//Qual categoria foi escolhida?
var CliqueCategoria = new TapGestureRecognizer();
CliqueCategoria.NumberOfTapsRequired = 1;
CliqueCategoria.Tapped += (s, e) =>
{
CriaLoading();
var stacklayout = s as Grid;
categoriaEscolhida = (Categorias)stacklayout.BindingContext;
ChamaProdutos();
};
GridContent.GestureRecognizers.Add(CliqueCategoria);
if (item.imagem != null && item.imagem != "")
{
int initIndex = item.imagem.IndexOf(',');
string image = "";
image = item.imagem.Substring(initIndex + 1);
try
{
GridContent.Children.Add(new CachedImage { Source = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(image))), VerticalOptions = LayoutOptions.FillAndExpand, DownsampleHeight = 60 }, 0, 0);
}
catch (Exception e)
{
GridContent.Children.Add(new CachedImage { Source = "error.png", VerticalOptions = LayoutOptions.FillAndExpand, DownsampleHeight = 50, HorizontalOptions = LayoutOptions.Fill, HeightRequest = 50, WidthRequest = 50 }, 0, 0);
}
}
GridContent.Children.Add(new Label { Text = item.nome, TextColor = Color.FromHex(item.corTexto), FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.CenterAndExpand, LineBreakMode = LineBreakMode.TailTruncation }, 0, 1);
if (column == 0)
{
column = 1;
}
else
{
column = 0;
row++;
}
}
}
async Task ChamaProdutos()
{
await CallingProdutosAsync();
await CallingAcompanhamentosAsync();
await Navigation.PushAsync(new Views.ProdutosView(codigoLoja, categoriaEscolhida, lstProdutos, lojaProx), true);
PopupNavigation.PopAsync();
if (lstProdutos == null)
DisplayAlert("Ops", "Verifique sua conexão com a internet e tente novamente.", "Ok");
}
//carregamento de dados para a tela de produtos
async Task CallingProdutosAsync()
{
lstProdutos = await Webservice.GetProdutosAsync(codigoLoja, categoriaEscolhida.idCategoria);
}
//este pode estar zerado
async Task CallingAcompanhamentosAsync()
{
categoriaEscolhida.acompanhamentos = new List<Acompanhamento>();
categoriaEscolhida.acompanhamentos = await Webservice.GetAcompanhamentoAsync(codigoLoja, categoriaEscolhida.idCategoria);
}
}
}
----------------更新------------ 现在,标签渲染器错误似乎不再发生了……但是默认+渲染器错误仍然存在……还有一个空引用异常(我认为这与我的标签渲染器代码中的构造函数有关)
最佳答案
您已将类命名为 LabelRenderer,该类已存在于 Xamarin.Forms.Platform.Android 命名空间中。
在程序集属性中,typeof(LabelRenderer)等同于typeof(Xamarin.Forms.Platform.Android.LabelRenderer),但我们需要它是typeof(neoFly_Montana.Droid.LabelRenderer)。
避免这些 namespace 冲突的简单方法是使用唯一的类名,例如 NeoFly_MontanaLabelRenderer。
并且在使用 Xamarin.Forms v2.5+ 时,我们需要使用重载的构造函数,我在下面添加了它。
using System;
using Android.Runtime;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using neoFly_Montana.Droid;
[assembly: ExportRenderer(typeof(Xamarin.Forms.Label), typeof(NeoFly_MontanaLabelRenderer))]
namespace neoFly_Montana.Droid
{
public class NeoFly_MontanaLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
}
}
using System;
using Android.Runtime;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using neoFly_Montana.Droid;
[assembly: ExportRenderer(typeof(Xamarin.Forms.Label), typeof(NeoFly_MontanaLabelRenderer))]
namespace neoFly_Montana.Droid
{
public class NeoFly_MontanaLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
public NeoFly_MontanaLabelRenderer(Context context) : base(context)
{
}
}
}
关于c# - 找不到 Xamarin.Forms.Platform.Android.LabelRenderer(xamarin 表单)的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49072039/
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha
C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
我已经看到了一些其他的问题,尝试了他们的建议,但没有一个对我有用。我已经使用Rails大约一年了,刚刚开始一个新的Rails项目,突然遇到了问题。我卸载并尝试重新安装所有Ruby和Rails。Ruby很好,但Rails不行。当我输入railss时,我得到了can'tfindgemrailties。我当前的Ruby版本是ruby2.2.2p95(2015-04-13修订版50295)[x86_64-darwin15],尽管我一直在尝试通过rbenv设置ruby2.3.0。如果我尝试rails-v查看我正在运行的版本,我会得到同样的错误。我使用的是MacOSXElCapitan版本10
我花了几天时间尝试安装ruby1.9.2并让它与gems一起工作:-/我最终放弃了我的MacOSX10.6机器,下面是我的Ubuntu机器上的当前状态。任何建议将不胜感激!#rubytest.rb:29:in`require':nosuchfiletoload--mongo(LoadError)from:29:in`require'fromtest.rb:1:in`'#cattest.rbrequire'mongo'db=Mongo::Connection.new.db("mydb")#gemwhichmongo/usr/local/rvm/gems/ruby-1.9.2-p0/g
我正在尝试以一种更类似于普通RubyGem结构的方式构建我的Sinatra应用程序。我有以下文件树:.├──app.rb├──config.ru├──Gemfile├──Gemfile.lock├──helpers│ ├──dbconfig.rb│ ├──functions.rb│ └──init.rb├──hidden│ └──Rakefile├──lib│ ├──admin.rb│ ├──api.rb│ ├──indexer.rb│ ├──init.rb│ └──magnet.rb├──models│ ├──init.rb│ ├──invite.rb│ ├─
我正在尝试在SUSEEnterprise11SP3上安装compass。我得到以下信息。有什么想法吗?geminstallcompassBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingcompass:ERROR:Failedtobuildgemnativeextension./usr/bin/rubyextconf.rbmkmf.rbcan'tfindheaderfilesforrubyat/usr/lib64/ruby/ruby.hextconffailed,exitcode1Gemfileswi
我的heroku应用崩溃了,因为它找不到模块“SecureRandom”。我在gemfile中指定了我的Ruby版本,我的计算机、gemfile和Heroku似乎都匹配Ruby版本号,尽管不是补丁号。其他帖子建议将usr/bin/heroku指向特定的Ruby文件,但我不确定该怎么做(我的应用程序中没有Herokubin)。这看起来像是Ruby版本错误。我该如何解决这个问题?classOrderItemHeroku日志:/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependenci