I seem to understand that to optimize an app you need to add the following
to your app class
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MyAppNamespace
{
public partial class App
{
}
}
Now if you have many Prism modules where do you add this line of code
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
Many thanks
You can place it anywhere, but typically you would include it in the App.xaml.cs. The "assembly" attribute will apply it to all pages in the project.
You would need the attribute in each project where you have XAML files. Some general rules:
You can place this on individual XAML based Views/Pages to Opt-In or Opt-Out of Xaml Compilation:
[XamlCompilation(XamlCompilationOptions.Compile)]
public class ViewA : ContentPage
{
}
[XamlCompilation(XamlCompilationOptions.Skip)]
public class ViewB : ContentPage
{
}
You can use it instead as an Assembly Attribute like you have shown which is what most people choose to do.
The important thing here is that you can only place this ONCE per project, and it is on a Project by Project basis. You can put it in any file you choose as that comes down to preference. Typically you see this in one of the following locations:
In Properties/AssemblyInfo.cs. Though most templates no longer include this file by default for SDK Style projects, many people (myself included) still prefer a central location to look for and add assembly level attributes
In App.xaml.cs like:
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace AwesomeApp
{
public partial class App : PrismApplication
{
}
}
In an implementation of IModule which resides in a separate project
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace AwesomeApp.Auth
{
public class AuthModule : IModule
{
}
}
Related
I am building razor pages app using .Net Core 2.0
What is the difference between declaring a property inside the .cshtml such as follows
#functions
{
public StandardListenerViewModel listener { get; set; }
}
and the one declared in the page model
public class SingleDeviceModel : PageModel
{
[BindProperty]
public StandardListenerViewModel listener { get; set; }
public void OnGet(StandardListenerViewModel lstner)
{
this.listener = lstner;
}
}
There's no real technical difference as far as the property is concerned whether it is declared in a functions block or a PageModel class. It still becomes a property of the generated class when the app is compiled. The difference is really one of code organisation.
Most people prefer to work with a PageModel class because it provides a clean separation between UI (markup) and request processing logic. And it is a lot easier to unit test logic. You just need to instantiate an instance of the PageModel class in your test.
Generally, functions blocks are more likely to be used in simple demos to make the code easier to follow for proof of concepts. They probably also provide an easier ramp for those moving to Razor Pages from PHP, classic ASP or ASP.NET Web Pages where having processing logic and UI markup in the same file is a common pattern.
Introduction:
I am starting with code from:
https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/Entry/Android
to study custom renderers. I am doing this because there is code that only executes on the android platform. Lets call this "androidMethod()" and belongs in the Android codebase (not the shared library). I have noticed that most of the examples I have found have utilized customRenderers for making platform specific UI modifications (like the example in the link) but I intend to make no changes to the UI, rather I am trying to place a platform specific method in a Xamarin.Forms ButtonOnClick() method as the code below indicates.
The code below is similar to the code you will find in the MyEntryRenderer.cs from the link but you will see that it was modified to apply to a button instead of an entry.
MyButtonRenderer.cs:
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using CustomRenderer;
using CustomRenderer.Android;
using Android.Content;
[assembly: ExportRenderer(typeof(MyButton), typeof(MyButtonRenderer))]
namespace CustomRenderer.Android
{
class MyButtonRenderer : ButtonRenderer
{
private Button androidButton;
public MyButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
//I want to be able to do something like this:
ButtonOnClick(androidMethod());
}
}
}
}
How do I get androidMethod(); to execute in this context. The samples I find are limited so please try to limit your response to something that would be compatible with the example. Thankyou!
if you want to execute a platform specific method, I would use DepenencyService instead of a Custom Renderer
I'm going to start a website which I know is going to be presented in multiple languages. However, for the first version we're only going to need the English version. Once the features are all working, we'll add the other languages.
Unfortunately since there are not enough enough features baked into Asp.Net Core, we have to use the Asp.Net MVC 5 for the website. My question has 2 parts:
Right now, which practice is considered the best approach for this? Using resource files and loading them in razor pages? Using a framework? Can we use the new localization and globalization features of Asp.Net MVC 6 somehow? Or is there a better alternative? I personally hate using the resource files. It adds too much clutter to the code.
Would you suggest just using plane text for now and then adding the Internationalization features to the website or start now and only add the translations?
I would use resource files, seems to be the easiest solution. You can also use a Database resource provider, so you have less clutter.
If you start with plain text, it will get more complicated and cumbersome to add the translations later. So I would not do that.
We use Smart internationalization for ASP.NET.
Features
Localize everything: HTML, Razor, C#, VB, JavaScript, .NET attributes
and data annotations, ...;
SEO-friendly: language selection varies the URL, and Content-Language is set appropriately;
Automatic: no URL/routing changes required in the app;
High performance, minimal overhead and minimal heap allocations; Unit testing support;
Smart: knows when to hold them, fold them, walk away, or run, based on i18n best practices.
How I use i18n in the project step by step:
Add the I18N nuget package to your MVC project.
in Web.config:
Add a folder named "locale" to the root of your site. Create a subfolder for each culture you wish to support. For example, /locale/fr/.
copy i18n.PostBuild.exe into locale folder
Right click on tne project name --> Properties --> Build Events:
in Post-build event command line:
"$(TargetDir)i18n.PostBuild.exe" "$(ProjectDir)\web.config"
In views use [[[some text]]] to translate it later
Build the project
Refresh Solution Explorer and push Show All Files
Include all files in "locale" folder into the project
Provide translation of the words in locale\fr\messages.po
In Global.aspx add :
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//other app start code
UrlLocalizer.UrlLocalizationScheme = UrlLocalizationScheme.Void;
}
}
Create DefaultController :
public class DefaultController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (Session["currentLanguage"] == null)
{
Session["currentLanguage"] = "en";
}
}
}
In HomeController add inheritance of DefaultController and SwitchLanguage(string lang):
public class HomeController : DefaultController
{
public HomeController() : base()
{
[AllowAnonymous]
public async Task<ActionResult> SwitchLanguage(string lang)
{
LocalizedApplication.Current.DefaultLanguage = lang;
Session["currentLanguage"] = lang;
return Redirect(Request.UrlReferrer.PathAndQuery);
}
}
}
In navigation bar View (_LoginPartial.cshtml in my case) add links to switch between languages:
#if (Session["currentLanguage"].ToString() == "fr")
{
<li class="navItem">#Html.ActionLink("EN", "SwitchLanguage", "Home", new { lang = "en", area = "" }, null)</li>
}
else
{
<li class="navItem">#Html.ActionLink("FR", "SwitchLanguage", "Home", new { lang = "fr", area = "" }, null)</li>
}
Build project, Start in Browser and enjoy!!!
see some help in:
https://www.codeday.top/2017/09/19/42409.html
UPDATE1
I've added RazorGenerator and etc...
After set custom tools, I've seen generated code for my razor pages.
Added this code in assembly
public class MyAreaRegistration : AreaRegistration
{
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("Dictionary_default", "MyDictionary/{Action}/", new { controller = "DictionaryControllerBase", action = "Index" });
}
public override string AreaName
{
get { return "MyDictionary"; }
}
#endregion
}
But when I open page by url /MyDictionary, i see "Unable to find the resource."
NOTE I use in my project MVC3 and Spring.Net
I use one controller (base controller) in another Assembly with razor pages.
In my project I make controller inherited from base controller, just it make some settings. But razor pages I wish to use from assembly.
How can I do it?
You could the RazorGenerator extension. I have detailed how this can be achieved in the following post. The idea is that the RazorGenerator extension would create a corresponding .cs file for each Razor view and it will update it every-time you make a change to the corresponding view. This way the Razor views will be precompiled in the class library along with their respective controllers and view models. The RazorGenerator.Mvc NuGet will then register a custom virtual path provider which will take care of resolving those views.
I have some code activities.
public class baseAct: CodeActivity
{
}
public sealed class C1: baseAct
{
}
public sealed class C2: baseAct
{
}
public sealed class C3: baseAct
{
}
And i use a custom wf desinger.
I would like set same icon to activites C1,C2,C3 without define activity designer.
There are something (AttributeTableBuilder or similar) to set icon?.
Add the icon to your solution, set its Build Action to Resoruce
In your Activity, set the ActivityDesigner.Icon to this image
Hardest part about this is getting the Uri right. If you have problems, just dump the image into the same folder as the designer.
<sap:ActivityDesigner.Icon>
<DrawingBrush>
<DrawingBrush.Drawing>
<ImageDrawing>
<ImageDrawing.Rect>
<Rect
Location="0,0"
Size="16,16"></Rect>
</ImageDrawing.Rect>
<ImageDrawing.ImageSource>
<BitmapImage
UriSource="RelativeUriToTheImage.bmp" />
</ImageDrawing.ImageSource>
</ImageDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</sap:ActivityDesigner.Icon>
I have a sample that illustrates exactly what you need to do. How to create a Custom Activity Designer with Windows Workflow Foundation (WF4)