.NET MAUI Is there a way to make the TabBar element have rounded corners? - .net-maui

I have been looking at the Shell class and it seems that they only have a few properties available regarding changing the look of the tabbar. I have also looked on Microsoft's docs and couldn't find any info.
I am specifically looking for solutions that work for android.

First, you need to define a Shellrenderer in your project to overwrite the method.
using Android.Content;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Xaminals.AppShell), typeof(Xaminals.Droid.MyShellRenderer))]
namespace Xaminals.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected overrideIShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new MyShellToolbarAppearanceTracker();
}
}
}
Second, The MyShellRenderer class overrides the CreateBottomNavViewAppearanceTracker method and returns an instance of the MyShellToolbarAppearanceTracker class, so you need to rewrite the return class to change the form of the tabbar.
Here is the code :
using AndroidX.AppCompat.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
namespace Xaminals.Droid
{
public class MyShellToolbarAppearanceTracker : IShellBottomNavViewAppearanceTracker
{
public MyShellToolbarAppearanceTracker(IShellContext context) : base(context)
{
}
public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
bottomView.SetBackgroundResource(Resource.Drawable.forms);
}
}
}
Last, you create a form.xml in your Resources/drawable and you can change the form of the shell tabbar.
Here is the code:
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
/>
</shape>
More information for Shellrenderer

Related

Regular Expression to validate ApplicationUser email address in ASP.net MVC5

I am creating a webapp in asp.net MVC5 which will only allow people with a certain domain to sign up.
From what I understand the easiest way is to use a regular expression. Is there any way to use Data Annotations to change the model, or do I have to play around with the view to achieve this?
Probably a bit too late now but I would suggest as follows:
I've have an app in which I need to modify some of ApplicationUser properties, I am trying something which haven't tested on real life yet, but my Unit Tests are passing so far, it could be useful for you.
Override Email property in ApplicationUser, and add a custom validation annotation:
[ValidateEmailDomain(ErrorMessage = "Not a valid email domain.")]
public override string Email { get; set; }
ValidateEmailDomain code:
using System.ComponentModel.DataAnnotations;
using System.Web;
namespace WATHEVER
{
public class ValidateEmailDomain: RequiredAttribute
{
public override bool IsValid(object value)
{
//code
}
}
}
Note that as ValidateEmailDomain inherits from RequiredAttribute it will become obviously obligatory, if you don't want it that way, you could validate it also when it's null.
Sorry for my English :/
with MVC 5 you're using ASPNET Identiy, and the basic properties are encapsulate inside IdentityUser, so for your case, you cannot have access direct to the field email, but yuo can use EF Fluent API to add some rules, the but part is that regularexpression attribute is not part of the EF Fluent API.
If you need to see how can you use EF Fluent API with ASPNET Identity:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{ }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//Define rules
modelBuilder.Entity<IdentityUser>()
.Property(u => u.Email).IsRequired();
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
Regards,

How to unregister a class in mono touch

In monotouch using c# I have used [Register("CpyRightCusTabVwCell")] above the afore mentioned class. Now I want to un-register that class. How do I do that in monotouch using C#?
using System;
using MonoTouch;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Runtime.CompilerServices;
using System.Net.Mime;
using NUnitLite.Runner;
namespace egUniSBPersHlthCareManager
{
[Register("CpyRightCusTabVwCell")]
public partial class CpyRightCusTabVwCell : UITableViewCell
{
public CpyRightCusTabVwCell(IntPtr handel):base (handel)
{
}
public CpyRightCusTabVwCell ()
{
}
}
}
You can't.
Class registration is for life (of the process).

Change VirtualPathProvider in MVC 5

I ported my MVC 4 project to MVC 5 and after that my views with is embedded as resources cannot be loaded. Problem is that when mvc search for view it uses view engine witch inherit from BuildManagerViewEngine. This class use FileExistenceCache with use VirtualpathProvider with is set through constructor. By default its MapPathBased provider when I change provider to my custom in HostingEnviroment no change is made in existing FileExistenceCache instances than my view is not founded.
I change VirtualpathProvider in Route config class but its to late. What is better place for this?
Thanks
Rather subclass existing 'IViewEngine' to use custom VirtualPathProvider. Then register your custom engine in Global.asax file.
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ViewEngines.Engines.Add(new MyViewEngine());
}
private class MyVirtualPathProvider: VirtualPathProvider {}
private class MyViewEngine : RazorViewEngine
{
public MyViewEngine()
{
this.VirtualPathProvider = new MyVirtualPathProvider();
}
}
}
This way you can also control which engine has priority by adding, inserting your engine at proper place in Engines collection.
As an alternative, you can use PreApplicationStartMethodAttribute to replace VirtualPathProvider, but this will change provider globally, for all standard IViewEngines.
[assembly: PreApplicationStartMethod(
typeof(MyNamespace.MyInitializer), "Initialize")]
Then you swap provider in public static method in your class:
public static class MyInitializer
{
public static void Initialize() {
HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());
}
}
There is good post by Phil Haack about it: Three Hidden Extensibility Gems in ASP.NET 4

XStreamAsAttribute not adding as attribute - xstream

I wrote a class which will be converted by xstream into xml .
I added #XStreamAsAttribute to add xmlns as an attribute . But it got added as a nested tag in the output
My class file is as follows
#XStreamAlias("GetConfigurationParametersResponse")
public class GetConfigurationParametersResponse
extends BaseResponse
{
#XStreamAlias("xmlns")
#XStreamAsAttribute
final String xmlns = "http://www.collab.net/teamforge/integratedapp";
#XStreamAlias("xmlns:ns2")
#XStreamAsAttribute
final String ns2="http://www.collab.net/teamforge/integratedapp";
#XStreamImplicit(itemFieldName="ConfigurationParameter")
protected List<ConfigurationParameter> configurationParameter;
public List<ConfigurationParameter> getConfigurationParameter() {
if (configurationParameter == null) {
configurationParameter = new ArrayList<ConfigurationParameter>();
}
return this.configurationParameter;
}
}
The output for this is as follows
<com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
<xmlns>http://www.collab.net/teamforge/integratedapp</xmlns>
<ns2>http://www.collab.net/teamforge/integratedapp</ns2>
</com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
But I need output as
<com.collabnet.teamforge.ia.GetConfigurationParametersResponse xmlns="http://www.collab.net/teamforge/integratedapp" xmlns:ns2="http://www.collab.net/teamforge/integratedapp">
</com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
Please help in finding out where I am going wrong .
I followed this tutorial http://x-stream.github.io/annotations-tutorial.html
You probably need to do the following:
xstream.processAnnotations(GetConfigurationParametersResponse.class);
If only the following is being called:
xstream.processAnnotations(BaseResponse.class);
Then you could use the #XStreamInclude annotation on BaseResponse as follows:
#XStreamInclude({GetConfigurationParametersResponse.class})
public class BaseResponse {
}
What worked for me was:
xstream.autodetectAnnotations(true);

Troubles with WCF client (for a non .Net service)

In a c# project, I have to query some web services which is not build with .Net (actually WebLogic).
Where I can query most of the web services with no problem, I have difficulties with one. When I call the method, I get the following error (stack trace removed) :
System.InvalidOperationException: There was an error reflecting 'in'.
---> System.InvalidOperationException: The top XML element 'in' from namespace '' references distinct types MyReference.DistantWS.firstMethodInType and MyReference.DistantWS.secondMethodInType.
Use XML attributes to specify another XML name or namespace for the element or types.
After a bit of googling, I conclude this is due because the distant service have two methods FirstMethod and SecondMethod, both with a complex FirstMethodRequest type having a property "In" as input parameter. However, the In parameter have two distinct types(respectively firstMethodInType and secondMethodInType).
I use svcutil for building the proxy code. This actually generate the code :
Pseudo code :
class firstMethodRequest
{
public firstMethodintype #in; // First occurence of a "in" parameter
}
class firstMethodintype
{
}
class secondMethodRequest
{
public secondMethodintype #in; // Second occurence of a "in" parameter
}
class secondMethodintype
{
}
Full code :
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="first-method", WrapperNamespace="http://mynamespace/ws/wsdl/first-method", IsWrapped=true)]
internal partial class firstMethodRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public firstMethodintype #in;
public firstMethodRequest() { }
public firstMethodRequest(firstMethodintype #in) { this.#in = #in; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="first-method-in-type", Namespace="http://mynamespace")]
public partial class firstMethodintype
{
private string site_origineField;
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="second-method", WrapperNamespace="http://mynamespace/ws/wsdl/second-method", IsWrapped=true)]
internal partial class secondMethodRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public secondMethodintype #in; // Problem is here
public secondMethodRequest() { }
public secondMethodRequest(secondMethodintype #in) { this.#in = #in; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName="second-method-in-type", Namespace="http://mynamespace")]
public partial class secondMethodintype
{
private string site_origineField;
}
As I don't control the output code, how can I properly solve my problem ?
thx in advance
[Edit] Don't know if it's related, but here is an extract of the WSDL definition :
<message name="first-method-in">
<part name="in" type="tp:first-method-in-type"/>
</message>
<message name="second-method-in">
<part name="in" type="tp:second-method-in-type"/>
</message>
[Edit 2] Also, if the source WSDL / Schema is not valid or respectful to the W3C standards, please tells me. I can negotiate with the customer to rewrite its WS
[Edit 3] If I manually patch the wsdl to (renamed the second part) :
<message name="first-method-in">
<part name="in" type="tp:first-method-in-type"/>
</message>
<message name="second-method-in">
<part name="inSecond" type="tp:second-method-in-type"/>
</message>
then the problem disappeared (but of course the call to the second method stop working)
Finally, I ask the customer to change its WSDL to avoid this name conflicts.
This solved the problem and is probably the simplest way to solve the issue.

Resources