I'm trying to use the new ObservableProperty attribute from the CommunityToolkit.MVVM. Any time I add it, I get 17 errors such as "The type MainViewModel already contains a definition for FileToPlay", or "Type MainViewModel already defines a member called 'OnFileToPlayChanging' with the same parameter types". These are all in the MainViewModel.g.cs file.
I'm using VS 2022 Community, and the project has a WPF Application project template targeting .NET6.
Sample code that generates the error is:
namespace CorePlayer.ViewModel
{
public partial class MainViewModel : ObservableObject
{
[ObservableProperty]
private string? fileToPlay;
}
}
Anyone have any idea what I could be doing wrong?
Thanks
I had this exact same problem. Searching for an answer led me to this question.
My application is a WPF app on .NET Core 3.1.
I fixed it by following the guidance at the end of this YouTube video, .NET Community Toolkit.
I chose my second project as a .NET Standard 2.1 project.
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
After updating Visual Studio to version 17.4.0 preview 6 (and making sure the class was marked "partial"), it now works.
Related
I am trying to create a simple report in my vs2019 with a class as the data model
I have a public class named 'persona'
I have a new wpf applicacion (.net 5)
I've create a new report (RDLC file)
I try to use a class as a data template to design the report
When I try to reference the class as the data source object, the class is not visible for the datasourtce wizard as you can see in the image below
If put that class in a diferent project, a class library project, I got a different error, as you can see in the images below
And whe I press the Finish button I got this new erro:
There is no clue about what to do,... does anyone have any idea ? What Am I doing wrong?
I have same problem. Try to use netstandard2.0 for model library, it works for me (vs2019 netcoreapp3.1)
I have created all my .gradle files (.jar and .aar) through Android Studio.
The .jar files compile to .dll files through the android bindings in Xamarin without any issues - and I can expand them in object explorer Visual Studio when including them as references.
My problem is with the .aar files.
I have the mapbox-android-core-1.4.0.aar file from the gradle in my Jars folder in Visual Studio.
The build action is set to "LibraryProjectZip" and under references I have included Xamarin.Android.Support.v7.AppCompat which then included all other android support dependencies.
The Android Compile version is Android 9.0
Android class parser: class-parse
Android codegen target: XAJavaInterop1
When I build i get the following error:
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
The official Xamarin troublehsooting says I must add the managed return to metadata which I did as follows:
<attr path="/api/package[#name='com.mapbox.android.core']/class[#name='FileUtils']/method[#name='FileUtils.LastModifiedComparator']" name="managedReturn">java.lang.Object</attr>
With this added it still has exactly the same error, so I am not sure where I am going wrong.
Do I need to add a partial class to Additions or is the attr> above sufficient - just using the wrong information inside it, or am I missing what the error is in the first place?
Error CS0535 'FileUtils.LastModifiedComparator' does not implement interface member 'IComparator.Compare(Object, Object)'
To fix this issue, try to add a partial class declaration for 'LastModifiedComparator' class and explicitly implement IComparator.Compare(Object, Object):
public partial class DeviceService
{
public void Compare(object a, object b)
{
...
}
}
In your case, the method name in <attr ...> tag should be Compare instead of the 'LastModifiedComparator' method.
Check the tutorial:
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/troubleshooting-bindings#possible-causes-6
Similar issue:
error CS0535 Class does not implement interface member
I am developing UWP app in xamarin. The application works on IOS, Mac , Android, Windows. I have created UWP project in it according to the tutorial given in developer.xamarin.com. But it giving error saying Accessibility.App namespace not found.
Here is my code:
namespace Accessibility.UWP
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
this.LoadApplication(new Accessibility.App());
}
}
}
According to your description, the app can't see Accessibility.App. As you claim that Android and iOS projects work there are two things that can cause the problem:
you don't have the reference to your Shared/PCL project in your UWP project (most likely).
you have possibly changed the namespace / class name in the Shared/PCL project to something else than Accessibility.App
This is usually caused by missing reference to the shared project or class library where Xamarin.Forms App class resides. From the description this project should be called Accessibility.
Right-click the UWP project select Add, Reference... then in Solution tab select the Accessibility project.
Also it might happen that the UWP project didn't pick up on the reference, so restarting Visual Studio might help as well.
If all fails, you can try to use class name binding with using. On top of the source code file add:
using FormsApp = Accessibility.App;
And then in code use:
this.LoadApplication(new FormsApp());
My issue was born in Does MvvmCross work in Xamarin Studio?. MvvmCross works fine in Visual Studio. However, I've been mandated to deploy this corporately using Xamarin Studio which is what their build server uses. I ran into the issue with System.Windows.Input.ICommand not being found by the compiler during my Xamarin Studio build. ICommands appear to be used quite extensively throughout MvvmCross for user commands (MvxCommand, which implements System.Windows.Input.ICommand). I've tried creating my own version of ICommand via the following code:
using System;
namespace Something.Common
{
public interface ICommand
{
event EventHandler CanExecuteChanged;
bool CanExecute(object parameter);
void Execute(object parameter);
}
}
All good, but still doesn't fix MvxCommand, because it implements the interface System.Windows.Input.ICommand. So I created my own version, MvxCommandEx, which is basically copied from Stuart's MvxCommand and implements my own ICommand (Something.Common.ICommand).
Lo and behold, it builds. It deploys. It got me all excited. But.... it didn't work. Any place I've bound a UI element to my custom ICommand just doesn't do anything. It's as if the binding from the Click event of the control to the view model's command is just not there anymore, whether I bind it in the .axml layout file... or use the CreateBindingSet method built-in to the view.
Now... I can get around this for some things... for instance, if I use a standard android Button, and invoke the view model's command manually from the built-in Click event, like:
btnAddScope.Click += (o, i) => { _ViewModel.RequestAddScope.Execute(null); };
it works, and I'm okay doing it this way in the interim until Xamarin releases their PCL support. But I'm using an MvxListView in another section of the app that was bound the old way using a syntax like:
lst.ItemClick = _ViewModel.RequestViewScope;
where lst is a MvxListView.
This won't work, however, because lst.ItemClick expects a System.Windows.Input.ICommand, and my ICommand isn't in that namespace.
Stuart provided explanations for this that supposedly are supposed to work. However, I'm feeling stupid for not being able to implement the ICommand in a way that actually works, when it feels like it should work... so before I go down a different avenue to address this, I wanted to see if anyone could shed light on what I'm doing wrong.
The easy solutions are:
either to provide your own implementation for the Xamarin version of System.Windows.Input.ICommand and to use this implementation
or to use the mvvmcross binaries which are built on the mac.
I'd recommend the first.
If you delete your Something.Common.ICommand code abd then put your MyCommand class implementation in the same project/assembly as your viewmodels, then they should build and run fine on both windows and on mac.
VS 2010 solution and Silverlight project builds fine, then:
I open MyView.xaml view in Expression Blend 4
Add sample data from class (I use my class defined in the same project)
after I add new sample design data with Expression blend 4, everything looks fine, you see the added sample data in the EB 4 fine, you also see the data in VS 2010 designer too.
Close the EB 4, and next VS 2010 build is giving me this errors:
Error 7 XAML Namespace http://schemas.microsoft.com/expression/blend/2008 is not resolved. C:\Code\source\...myview.xaml
and:
Error 12 Object reference not set to an instance of an object. ... TestSampleData.xaml
when I open the TestSampleData.xaml I see that namespace for my class used to define sample data is not recognized.
However this namespace and the class itself exist in the same project!
If I remove the design data from the MyView.xaml:
d:DataContext="{d:DesignData /SampleData/TestSampleData.xaml}"
it builds fine and the namespace in TestSampleData.xaml is recognized this time??
and then if add:
d:DataContext="{d:DesignData /SampleData/TestSampleData.xaml}"
I again see in the VS 2010 designer sample data, but the next build fails and again I see studio cant find the namespace in my TestSampleData.xaml containing sample data.
That cycle is driving me crazy. Am I missing something here, is it not possible to have your class defining sample design data in the same project you have the MyView.xaml view??
cheers
Valko
I know this is and old question, but do you have the line mc:Ignorable="d" in your xaml? Without this line you will get this error.
Add this namespace
xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.TestSampleData"
Add this resource to a resource dictionary
<SampleData:TestSampleData x:Key="TestSampleData" d:IsDataSource="True"/>
Reference like this in your xaml
d:DataContext="{Binding Source={StaticResource TestSampleData}}"
I realise this is an old(ish) question but I hope this helps someone.