Partial declarations must not specify different base classes windows phone - windows-phone-7

i'am getting this error her:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
my xaml is lile this:
<UserControl x:Class="GameMemory.MainPage"..../>
besides it returns erro: The call is ambiguous between the following methods or properties: 'GameMemory.MainPage.InitializeComponent()' and 'GameMemory.MainPage.InitializeComponent()'
any ideas please?

It seems that one of the assemblies you referenced has a class named UserControl.
Check your using declarations.

Related

Create a Base TagHelper with no TargetElement

I'm creating a library of MVC6 TagHelpers for a large project.
I find myself writing certain functionality in these TagHelpers again and again.
I'd like to make a base TagHelper that all the others inherit from to remove all the duplicated code.
The issue is this - suppose I create a base TagHelper as below:
public class BaseTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
//Some implementation...
}
}
Now, when I go to write a view, I will have intellisense suggesting the taghelper <base>.
Is there any way I can tell intellisense that this isn't a TagHelper I actually want to use, just a base class containing implementation common to other TagHelpers I've created?
Create it as an abstract class, see some examples in the official MVC Core repo like CacheTagHelperBase
public abstract class BaseTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
//Some base implementation...
}
}

Xamarin WebView - Call C# Method

Is there a way in Xamarin's WebView that allows me to attach javascript events to my html elements and call C# method.
I could easily do this in Android by using JavaScriptInterface
<video width="320" height="240" controls="controls" poster='poster.gif'
onclick="window.JSInterface.startVideo('file:///sdcard/test.3gp');"
How would I manage to this in Xamarin
Create a JavaScript Interface Class
Create a C# class that contains methods to be called from JavaScript.
If you are targeting Android API level 17 or later, this
JavaScript-to-C# interface class must annotate each
JavaScript-callable method with [JavascriptInterface] and [Export]
as shown in the following example. If you are targeting Android API
Level 16 or earlier, this interface class must implement
Java.Lang.IRunnable as explained in Android API Level 16 and
Earlier (later in this recipe):
Create a C# class that is derived from Java.Lang.Object. In the following example, we name our class MyJSInterface and implement a
method to display a toast when it is called from JavaScript:
public class MyJSInterface : Java.Lang.Object
{
Context context;
public MyJSInterface (Context context)
{
this.context = context;
}
public void ShowToast ()
{
Toast.MakeText (context, "Hello from C#", ToastLength.Short).Show ();
}
}
Annotate each method that is to be exposed to JavaScript with [Export] and [JavascriptInterface] (see IJavascriptInterface
for more information about the JavascriptInterface annotation). In
the following example, the ShowToast method is annotated so that it
can be called from JavaScript. Note that you must include the
Java.Interop and Android.Webkit using statements as shown in this
example:
using Java.Interop;
using Android.Webkit;
...
[Export]
[JavascriptInterface]
public void ShowToast ()
{
Toast.MakeText(context, "Hello from C#", ToastLength.Short).Show();
}
Add a project reference to Mono.Android.Export (so you can use the [Export] annotation):
1.In Visual Studio, right-click References in the Solution Explorer and select Add Reference.... In Xamarin Studio,
right-click References in the Solution Pad and select Edit
References....
2.In the search field, enter Mono.Android.Export. When you have located it, enable the check mark next to it and click OK.
Refer :
http://dotnetthoughts.net/how-to-invoke-c-from-javascript-in-android/
https://developer.xamarin.com/recipes/android/controls/webview/call_csharp_from_javascript/
https://developer.xamarin.com/samples/monodroid/WebViewJavaScriptInterface/
https://developer.xamarin.com/api/type/Android.Webkit.JavascriptInterface/

How to connect View and ViewModel using MVVMCross for Windows Phone Universal Platform?

I have a pcl dll (Xamarin) and all the viewmodels, models, services, interfaces, converters are on this project.
I am already using this core on Android and IOS and now will start the Windows Phone app.
My main question for now is, how do I make a viewmodel the datacontext for a view. For sample: LoginViewModel.cs (core) and LoginView.xaml...
I am using MVVMCross and The Windows Phone project is 8.1
Than you in advance.
Updating:
I tried this:
<views:MvxWindowsPage
x:Class="Tocalivros.WindowsPhone.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Tocalivros.WindowsPhone.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:Cirrious.MvvmCross.WindowsCommon.Views"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
public sealed partial class LoginView : MvxWindowsPage<LoginViewModel>
{
public LoginView()
{
this.InitializeComponent();
}
But now I get this error: "Severity Code Description Project File Line
Error CS0263 Partial declarations of 'LoginView' must not specify different base classes"
Based on samples, I tried a different aproach, instead of making the view of type view model, I create a ViewModel as a property and set it as DataContext for the view.
Like this:
public sealed partial class LoginView : MvxWindowsPage
{
public new LoginViewModel ViewModel
{
get { return (LoginViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
public LoginView()
{
this.InitializeComponent();
this.DataContext = ViewModel;
}
But this way the viewmodel wont be initiated with the required parameters... (IServices)
It makes me think the better aproach is the first:
public sealed partial class LoginView : MvxWindowsPage<LoginViewModel> but I get error...
You can do like with every other platform in MvvmCross.
public class LoginPage : MvxWindowsPage<LoginViewModel>
{
}
Inside your view you will see something like this:
<views:MvxWindowsPage
x:Class="somenamspace.Views.LoginPage">
<!-- Put your layout here -->
</views:MvxWindowsPage>
The datacontext is now done for that view.

My databinding fails, is the path wrong?

I'm trying to create a simple RSS news aggregator. But I've done something wrong with the binding.
The xaml:
<phone:LongListSelector
x:Name="MainLongListSelector"
Margin="0,0,-12,0"
ItemsSource="{Binding Path=News.List}"
SelectionChanged="MainLongListSelector_SelectionChanged">
The code behind:
(mainpage)
public MainPage()
{
InitializeComponent();
// Set the data context of the LongListSelector control
// to the sample data
DataContext = App.ViewModel;
(viewmodel)
public class NewsViewModel : BaseViewModel
{
public NewsRepository News { get; private set; }
}
The NewsRepository is just an model object holding the List<obj> List. Could anyone point me in the direction where thing goes sideways?
The app runs just fine but the single item in the List I've put in manually does not show up in the application :-(
I've set and breakpoint at the assignment of the DataContext to the the viewmodels content its there...
Both NewsViewModel and NewsRepository have to implement INotifyPropertyChanged.
It would be easier if you use ObservableCollection<obj> as a source of your binding instead of custom NewsRepository object.

Inheriting user control from an other user control

I am developing windows phone 8 app. Is would like to have some user controls which they inherit from a specific user control. I define my parent user control like this:
public abstract class WidgetsUserControl : UserControl
{
}
and the child like:
public partial class childControl : WidgetsUserControl
{
}
but it get error in defining abstract which says : "Missing partial modifier on declaration of type 'project1.WidgetsUserControl'; another partial declaration of this type exists"
what am i doing wrong?
It's complaining that you don't have the "partial" keyword in your definition of the WidgetsUserControl class. You probably have a corresponding XAML file for WidgetsUserControl that is partially defining that class, so here, you need to specify that it is partially defined as well.
public abstract partial class WidgetsUserControl : UserControl
Please note that if you go in this direction, then you also need to make the childControl definitions consistent. That is, in the code you would have:
public partial class childControl : WidgetsUserControl
and in the XAML, you will also need to specify that the childControl is a WidgetsUserControl, not just a simple UserControl:
<project1:WidgetsUserControl>
</project1:WidgetsUserControl>
Although this will work, a problem you will run into with this is that the Visual Studio Designer will complain that it can't create an instance of WidgetsUserControl (because it is abstract). This makes visualizing and editing the childControl a bit difficult. To solve this, my suggestion would be to just do away with the "abstract" in the base WidgetsUserControl. If you really want the base class to be abstract, then see here for other suggestions:
Abstract class in designer
This works good:
Code behind for parent user control:
public abstract partial class WidgetsUserControl : UserControl {
...
}
xaml for parent class:
<UserControl
...
xmlns:we="clr-namespace:project1"
...>
</UserControl>
code behind for child user control:
public partial class childControl : WidgetsUserControl {
...
}
xaml for child user control:
<we:WidgetsUserControl x:Class="project1.childControl"
...
xmlns:we="clr-namespace:project1"
...>
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}"></Grid>
</we:WidgetsUserControl>

Resources