The type 'page' does not support direct content - uno-platform

I create new Uno Cross-Platform App 2.2 from template.
When I open Shared->MainPage.xaml in doesn't open designer in code view there is a underlined error The type 'page' does not support direct content
<Page
x:Class="App6.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock Text="Hello, world!" Margin="20" FontSize="30" />
</Grid>
</Page>

This is an Intellisense issue which happens when the project selector (the DropDown at the top of the XAML editor) is not on the UWP project, but rather on iOS, Android or another platform.
If you select the UWP project, close the editor, and re-open it again, the errors will disappear.
As of Visual Studio 2019 16.5 the issue is still present, but is likely to be addressed in a future version.

At the beginning I can use designer to edit MainPage.xaml in Shared folder, after one moment (there was an error that crashed my VS) not any more...
So solution is to move MainPage.xml to UWP project, edit there, and than move it back.
That's work for now.
Maybe it would work with linked file.

I used Blend for Visual Studio to open and edit the file. The next time I opened the project with VS the problem was fixed.

Related

How to change the cancel icon in Xamarin Forms Shell SearchHandler

I have a Xamarin Forms Shell app where I have implemented the Shell SearchHandler. The cancel button shows a book image.
This only occurs on iOS - on Android, there is no cancel button.
My xaml looks like this:
<Shell.SearchHandler>
<controls:RouteSearchHandler
x:Name="RouteSearch"
BackgroundColor="White"
ClearPlaceholderCommand="{Binding ClearSearch}"
ClearPlaceholderIcon="{StaticResource Cancel}"
DisplayMemberName="Street1"
SearchBoxVisibility="{Binding TopSearchVisibility, Converter={StaticResource visibleConvert}}"
ShowsResults="True" />
</Shell.SearchHandler>
How do I change the cancel icon from a book to another fonticon or image?
It seems a potential issue , the team set a default(book) icon on Clear button.
Workaround
You can prepare a small/transparent image and place it in Resources folder in iOS project , and set ClearPlaceholderIcon with it, then the problem should be solved .
And Feel free to file the feature request on github :https://github.com/xamarin/Xamarin.Forms/issues.

Can not Navigate to Master Detail Page

i have axamarin app with login page that leads to modules launcher landing page
one of those modules is a master details page
every thing is working fine from VS (debug / release) ether emulator or real device
however out of VS, from emulator or device itself if i run the app everything work fine except the navigation to master detail page (without any response)
i tried to navigate to a detailed page directly (without the master page) it works
i tried to put a "/" at the start or remove it , i tried "/NavigationPage" or without it
still not working from the app outside VS.
i did the latest update (7.2.0.1422)
here is my xml codes :
navigation button from landing page
<ImageButton Grid.Row="1"
Grid.Column="2"
HeightRequest="80"
BackgroundColor="WhiteSmoke"
Source="homescreenbtn12.png"
Command="{Binding NavigationCommand}"
CommandParameter="NavigationPage/MwaslaMasterDetailPage"
IsVisible="{Binding CurrentUser.IsTPEmplyess}"/>
2.master details page it self
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="TPS.Modules.Mwasla.Views.MwaslaMasterDetailPage"
xmlns:views="clr-namespace:TPS.Modules.Mwasla.Views;assembly=TPS.Modules.Mwasla">
<MasterDetailPage.Master>
<views:MwaslaMasterPageMenu/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:MwaslaContactUsPage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
the normally navigation command
async void ExecuteCommandName(string parameter)
{
await NavigationService.NavigateAsync(parameter);
}
kindly help
There are a few issues I want to address here...
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="TPS.Modules.Mwasla.Views.MwaslaMasterDetailPage"
xmlns:views="clr-namespace:TPS.Modules.Mwasla.Views;assembly=TPS.Modules.Mwasla">
<MasterDetailPage.Master>
<views:MwaslaMasterPageMenu/>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<views:MwaslaContactUsPage/>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
Core Concepts
In this sample there are essentially 3 pages that need to be understood...
The Master Page (MwaslaMasterPageMenu)... it's fine if you want to separate the View for the Master into another XAML page but remember that this should NOT have it's own ViewModel nor should you attempt to set AutowireViewModel on that page.
The MasterDetailPage... this is the actual root navigation context that you are navigating from. This is the page that requires the ViewModel which you have explicitly set AutowireViewModel on
The Detail Page (MwaslaContactUsPage in a NavigationPage)... while this is technically correct for a Xamarin.Forms app and would allow you navigate to /MwaslaMasterDetailPage, it's not recommended that you do this. You should instead be explicit in setting the Detail /MwaslaMasterDetailPage/NavigationPage/MwaslaContactUsPage
Issues with Navigation
Navigation in Prism.Forms is based on the Page which you want to Navigate from in context. This is why in the past there requirements that the Navigation service was a named parameter. Before Prism resolves the ViewModel, it first constructs a new instance of the NavigationService and provides it the navigation context (the Xamarin.Forms.Page aka the View) that the ViewModel will be attached to.
Fixes
First you'll want to move all of the logic from the MwaslaMasterPageMenuViewModel and move it to the MwaslaMasterDetailPageViewModel
Get rid of the MwaslaMasterPageMenuViewModel and remove the AutowireProperty from the MwaslaMasterPageMenu.xaml
Remember that a MasterDetailPage is meant to be the NavigationRoot. This means that if you look at the MasterDetailPage's Parent, it should be your App.
Remember that in order to get the classic "Hamburger" look that people typically want with the MasterDetailPage your Detail needs to be a NavigationPage. In order to achieve this correctly you should refrain from explicitly setting the Detail Page so that you properly navigate to any detail page within the MasterDetailPage, ie /MyMasterDetailPage/NavigationPage/ViewA
When considering the previous comment remove references like /MyMasterDetailPage or /NavigationPage/MyMasterDetailPage
Navigating from the Master aka "Menu"
Remember that when you're navigating from the Master Page aka the Menu, you're navigating not from the Master Page at all but from the MasterDetailPage. As such you will simply do a relative navigation like NavigationPage/ViewA or NavigationPage/ViewB for anything that will change out the Detail Page.
finally it works
thanks Dan Siegel for detailed answer
It Work like Magic

Xamarin NetStandard SfListview Item tapped event not firing?

This is just as the title suggests. I've updated my Xamarin Forms project to a 1.6 NetStandard project and now the tapped event on my SfListView isn't working (It just doesn't fire at all).
Does anyone has any suggestions of what could be wrong or have faced anything like this?
EDIT
this is xaml code for SfListView:
<StackLayout HeightRequest="15" Grid.Row="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<xForms:SfListView Orientation="Horizontal" ItemSize="128" ItemsSource="{Binding Categories}" SelectionBackgroundColor="Transparent" IsScrollBarVisible="False">
<xForms:SfListView.ItemTemplate>
<DataTemplate>
<cells:CategoryCell />
</DataTemplate>
</xForms:SfListView.ItemTemplate>
<xForms:SfListView.Behaviors>
<behaviors:SfSelectedItemBehavior Command="{Binding FilterCommand}" />
</xForms:SfListView.Behaviors>
</xForms:SfListView>
</StackLayout>
this structure was working before the update. I use a behavior for item selection.
We have checked with the reported query “SfListView ItemTapped event does not trigger after updating the NetStandard Library” from our side. Unfortunately the reported issue does not occur at our end and the ItemTapped event is fired as expected.
For your reference, we have attached the working sample link below.
Sample link: http://www.syncfusion.com/downloads/support/directtrac/190562/ze/SfListViewSample-670965361
Can you please check in your device whether the issue reproduces in our sample also?
If so, Can you please share the below details?
Whether the reported issue occurs in particular device or all devices? (Can you please share the details of your tested device)
Whether the issue is produced in particular platform?
Whether the issue is produced in particular version of Xamarin.Forms and SfListView? (In our sample, we used XForms (v2.3.4.280) and SfListView(v15.3.0.33))
Also can you please share the share the template in which the SfListView items are loaded?

mvvm light Winforms dll project, how can I load the ViewModelLocator

I am working on a winforms project in c#. The project is an outlook plugin, so no hopes of totally converting to mvvmlight/wpf as it's a winforms dll project.
I am however trying to come up with a way to use MvvM Light and WPF with the ElementHost. The issue I have is getting access to the ViewModelLocator. Normally, this gets added in the App.xaml like this:
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
and is available to a view via :
DataContext="{Binding MyViewModel, Source={StaticResource Locator}}"
In my case, I don't have an App.xaml, nor do I have a program main() method where I can bootstrap the framework (as this is a dll project, not an application). I tried the following in my WPF usercontrol (hosted in an elementhost), but it doesn't work:
DataContext="{Binding MyViewModel, Source={StaticResource Locator}}"
...
<UserControl.Resources>
<ResourceDictionary>
<wpf:ViewModelLocator x:Key="Locator"
d:IsDataSource="True" />
I think it's not working because it's getting declared after its called. This would have been a compromise anyway as I would have needed that code in every view, so I'm kind of glad it didn't work.
Any suggestions how I can get to the ViewModelLocator??
Thanks,
Jeff
So I figured out what to do to solve this. It's not perfect, but it works. In the end, I have no Application to load the bootstrap, so what I really needed was a way to have a view get to the ViewModelLocator so I could databind the view. To do this I made the MyViewModel property static on the ViewModelLocator class and then I changed my DataContext line in the xaml (the view) as follows:
DataContext="{x:Static wpf:ViewModelLocator.MyViewModel}"

No Property of name Image found for Button on Windows Phone

I'm getting an issue I don't understand. I have a Button with an image defined with the following code :
<Button Image="SearchFilterIcon.png"
Grid.Row="0"
Grid.Column="1"
Clicked="OnButtonFilterClicked" />
This works well on Android. The image is displayed on my button but when I launch the Windows Phone application, I get a XamlParseException which says that : No Property of name Image found.
How is it possible? The Button widget isn't the same on Android and Windows Phone?
If you do the following:-
Button objButton1 = new Button();
objButton1.Image = (FileImageSource)ImageSource.FromFile("testImage1.png");
objStackLayout.Children.Add(objButton1);
this.Content = objStackLayout;
Then it will work (via code-behind).
The Button control always had the Image property, even in Xamarin.Forms v1.2.2x, so this is not a new property introduced and nothing to do with having the latest packages installed.
As a workaround perhaps you should consider giving the XAML Button a x:Name as in:-
<Button x:Name="myButton1"/>
And then assign the image from code-behind:-
myButton1.Image = (FileImageSource)ImageSource.FromFile("testImage1.png");
Update 1
This was a case of very old libraries being used (v1.0.6186). Once the project is reupdated to the latest binaries for v1.2.3x, then this works fine.
The Button.Image is available on WP, just as it is on iOS and Android. You probably don't have the latest nuget (1.2.3) installed for WP, or you have multiple versions installed.
The buttons in XAML for Windows Phone simply do not provide an Image property. Thus, you cannot add an image to the button as the API doesn't support this. What you have to do is to create a control template that contains the text and the image.
Button documentation
Try some like:
<Button Click="OnButtonFilterClicked">
<Button.Background>
<ImageBrush Stretch="Fill" ImageSource="/SearchFilterIcon.png"/>
</Button.Background>
</Button>
instead of "Clicked" and "image" properties.

Resources