When I create a new Razor page in Visual Studio 2017, the separated code behind file did not get created.
This is the screenshot of the problem highlighted.
We can see the Razor page called List.cshtml does not contain the code behind file. Contrast that with the default page about.cshtml, for example.
1 - Right click on "resturants", add class:
2 - in your case, call it List.cshtml.cs. This will create the code behind. It nows needs wiring up. Open the class that has been created.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
//Add the MVC usings
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
//TODO The namespace will be correct in your code
namespace app_name.Pages.resturants
{
//public class List
//TODO correct the model name and inherit PageModel
public List1Model : PageModel
{
public void OnGet()
{
}
}
}
3 - In List.cshtml:
#page
#model app_name.Pages.resturants.List1Model
#{
}
More information can be found here on modifying the code behind https://learn.microsoft.com/en-gb/aspnet/core/data/ef-rp/sort-filter-page?view=aspnetcore-5.0
When using the FormsApplication base class with a brand new Xamarin.Forms app using Caliburn.Micro, I end up with an empty navigation bar at the top of my screen. I assume it's being created by Caliburn.Micro somehow, because an out-of-the-box Xamarin.Forms app doesn't have that.
Is there any way I can use Caliburn.Micro with Xamarin.Forms without this navigation bar?
I have not used Caliburn.Micro, but I am assuming that it is wrapping your page with a NavigationPage, as what you describe is what would happen if so.
You should be able to hide that navigation bar by setting a simple attribute in your page like so:
<ContentPage NavigationPage.HasNavigationBar="false"
..... >
</ContentPage>
If you are not using XAML pages and doing all of your UI in code instead, then you can do it this way within your page constructor:
NavigationPage.SetHasNavigationBar(this, false);
If you are using a Shell, (if you chose any of Visual Studios three Templates when first creating your project, you probably are) NavigationPage.HasNavigationBar="False" won't work. Try adding this line of code to each of your ContentPages
Shell.NavBarIsVisible="False"
This drove me nuts for a while as every answer I've seen for the code behind is a partial answer.
Lets say in your App.Xaml.cs file you have your NavigationPage constructor set like this:
MainPage = new NavigationPage(new Astronomy.MainPage());
You then have to go into the MainPage code behind and add code to remove the NavBar: you can't add the line to the app constructor.
public MainPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
}
So glad I finally figured this out! It's been causing me a headache for a while!
It works for me:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.Window.AddFlags(WindowManagerFlags.Fullscreen); // hide the status bar
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
int uiOptions = (int)Window.DecorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
Window.DecorView.SystemUiVisibility =
(StatusBarVisibility)uiOptions;
}
If you are using Xamarin Forms 3.x try this in the constructor
SetValue(NavigationPage.HasNavigationBarProperty, false);
InitializeComponent();
After updating the MvvmCross nuget packages(to 8.0.2) and Xamarin Forms neget packages (to 5.0.0), I need to put this option explicitly.
put NavigationPage.HasNavigationBar="False" on your xaml ComtentPage
or MvxContentPage
New Here! My first comment
Just too confirm that "Cedric Moore"s Answer works!
Thank you, spent hours at this and this finally worked!
At the top of your Page(Located inside "Views" folder Default)
(AboutPage.xaml) is the starting one and the one i am using for this example.
Inside the <> of ContentPage, add Shell.NavBarIsVisible="False"
Example:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="YourNameHere.Views.AboutPage"
xmlns:vm="clr-namespace:YourNameHere.ViewModels"
Title="{Binding Title}"
Shell.NavBarIsVisible="False">
Hi am using the Glass mapper in combination with Sitecore MVC. I created model below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Test
{
using Glass.Mapper.Sc.Configuration.Attributes;
[SitecoreType(AutoMap = true)]
public class GlassTestModel
{
public virtual string Title { get; set; }
}
}
this is my view
#inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Test.GlassTestModel>
<div>
<h2>Hello</h2>
<h2>#Model.Title</h2>
</div>
I also tried this first line
#model Test.GlassTestModel
and this one
#inherits System.Web.Mvc.WebViewPage<Test.GlassTestModel>
I created a view rendering in Sitecore. configured the model to use above.
When I render the view the model fields don't get filled. When I test in a controller I use for other controller view like below:
ISitecoreContext ctx = new SitecoreContext();
var item = ctx.GetCurrentItem<Test.GlassTestModel>();
I do get the title field. Any ideas?
I migrated my solution to V4 of the Glass.Mapper package. This works. With V3 I can't get the automapping to work.
I'd like to know if there is a way to add a button in scene view when in edit mode in unity.
I'd like to choose an option from the gameobject menu and then deactivate it when the button on scene is clicked (before pressing run)
Is this possible please?
I think you are asking about Unity3D game engine. Well, by means of Editor scripts you can add a button in Editor mode. For example:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class LevelChunksAnalyser : MonoBehaviour {
[MenuItem("Level Chunks/Update Metadata")]
public static void UpdateLevelChunksMetadata()
{
Debug.Log("Yo");
}
}
I'm writing my own membership provider (actually just extending the built-in one) and MembershipProvider stays red with an error that it cannot be resolved, even though I've added System.Web.Security:
public sealed class MRCMembershipProvider : MembershipProvider
{
//code here
}
Anyone got any ideas why this would be happening?
Make sure that you have added reference to the System.Web.ApplicationServices.dll assembly which is where this class is defined as stated in the documentation:
Namespace: System.Web.Security
Assembly: System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)
It works only when the namespace for the MVC application is present.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
namespace MvcApplication6
{
public sealed class MRCMembershipProvider : MembershipProvider
{
}
}