tes*_*ing 13 c# custom-renderer xamarin xamarin.forms
今天我更新到Xamarin.Forms 2.5.0并看到,我得到以下警告:
警告CS0618'Forms.Context'已过时:'版本2.5后,上下文已过时.请改用当地语境.'
我怎样才能获得本地环境而不是Forms.Context?Android上下文意味着什么?
警告CS0618'ButtonRenderer.ButtonRenderer()'已废弃:'从2.5版开始,此构造函数已过时.请改用ButtonRenderer(Context).
在我,ButtonRenderer我只有OnElementChanged()方法,所以我应该在这里改变什么?只需添加一个ButtonRenderer(Context)构造函数?如果我在我的平台渲染器类中执行此操作,我仍然会收到警告.有人有例子吗?在官方文件没有提到它,谷歌也不会带来一些有用的结果,除了开源代码ButtonRenderer.此更改还涉及许多其他渲染器类.
有没有人经历过其他变化,制动插件等等?
PS:我也没有发现,什么时候Device.Windows被弃用了.现在我用它取而代之Device.UWP.
cva*_*eek 21
我有一个相同的问题,SearchBarRenderer我需要做的就是修复它是这样添加一个构造函数:
public ShowSearchBarRenderer(Context context) : base(context)
{
}
Run Code Online (Sandbox Code Playgroud)
希望能回答你问题的第二部分.
Bra*_*ick 12
这里有两个问题:
Xamarin.Forms.Forms.Context已过时的当前上下文?将重载的构造函数添加到每个自定义渲染器
这是一个使用a的例子 ButtonRenderer
[assembly: ExportRenderer(typeof(CustomButton), typeof(CustomButtonRenderer))]
namespace MyApp.Droid
{
public class CustomButtonRenderer : ButtonRenderer
{
public CustomButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
//ToDo: Customize Button
}
}
}
Run Code Online (Sandbox Code Playgroud)
安装@Motz的CurrentActivityPlugin.
现在,您可以CrossCurrentActivity.Current.Activity在需要访问当前活动时进行呼叫.
这是一个如何在Xamarin.Forms中打开应用程序设置的示例.
[assembly: Dependency(typeof(DeepLinks_Android))]
namespace MyApp.Droid
{
public class DeepLinks_Android : IDeepLinks
{
Context CurrentContext => CrossCurrentActivity.Current.Activity;
public Task OpenSettings()
{
var myAppSettingsIntent = new Intent(Settings.ActionApplicationDetailsSettings, Android.Net.Uri.Parse("package:" + CurrentContext.PackageName));
myAppSettingsIntent.AddCategory(Intent.CategoryDefault);
return Task.Run(() =>
{
try
{
CurrentContext.StartActivity(myAppSettingsIntent);
}
catch (Exception)
{
Toast.MakeText(CurrentContext.ApplicationContext, "Unable to open Settings", ToastLength.Short);
}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6246 次 |
| 最近记录: |