Cannot pass class as parameter to command


Kitten

I'm new to programming and I have my pass class that I created with difficulty <Window.Resources>as XAMLa parameter to a command.

  <Window.Resources>
      <local:RegisterWindowViewModel x:Key="RegViewModel"/>
      <local:RegisterValidationConverter x:Key="RegValid"/>
      <local:UsersViewModel x:Key="UVM"/>
  </Window.Resources>

This is the button with the command binding

    <Button Name="signupButton" DataContext="{StaticResource UVM}"
            Height="50" Width="150" BorderBrush="Black" BorderThickness="2" 
            FontSize="20" FontWeight="SemiBold"
            Style="{StaticResource AccentedSquareButtonStyle}"
            Command="{Binding GetRegisterItemCommand}"
            CommandParameter="{Binding RegViewModel}">
        Sign Up
    </Button>

I don't think this code CommandParameter="{Binding RegViewModel}"is correct, but I just don't know how to replace it...

So I get an object instead of nullmine in the command function . The function itself is ok; I've tested it a lot TextBox, e.g. trying to pass another object( ) and it works fine.

I just don't understand the syntax.

Is it even possible to pass the class created in the resource?

I will be very grateful for your help.

ice thorn

The way you are trying to use shows that it can find RegViewModelthe current one DataContext.

To point to your viewmodel itself, lets say the source of the binding is your binding RegViewmodelwith the following changes. In this case the full amount RegViewModelwill be passed toCommandParameter

CommandParameter="{Binding Source={StaticResource RegViewModel}}"

Related


Cannot pass subtype of abstract class as parameter to function

Martin Novosad I followed the BloC tutorial and did according to them, I have a Bloc with this method @override Stream<FridgeState> mapEventToState(FridgeEvent event) async* { .. } where FridgeEvent is an abstract class abstract class FridgeEvent { const

Pass command as parameter in bash

PSKP I have a simple script that takes the first argument from the command line and prints hello, first_arg. But when I pass |lsit is printing the files in the current directory. my script file #! /bin/bash echo "Hello, $1." I have tried many ways echo "Hell

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

cannot pass char *** as parameter

Bisla It's easy to see the tasks to be done here. Read a list of files and pass it to another function. Why doesn't this work. When I try to store the filename in a local char** it works fine, but I can't send it back via a pointer. gives segmentation fault. i

Pass the class name as a parameter

1110101001: I have 3 classes called RedAlert, YellowAlertand BlueAlert. In my class AlertControllerI want a method like this: public void SetAlert(//TAKE IN NAME OF CLASS HERE//) { CLASSNAME anInstance = new CLASSNAME(); } So, for example, I want to: Aler

Pass an array as a parameter to a class

Nick Sims: I'm trying to pass an array as a parameter to another class, but keep getting the error "error: incompatible types: dot cannot be converted to int[]" The first part of my code is: public Circle(int n, int x, int y) { radius = n;

Pass class type as parameter

belt: Pass type as parameter to api User 872858: You can receive Class as parameter like below, buildCriteriaQ(Class<?> parentClass) { CriteriaBuilder cb = factory.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityClass); R

Pass a Scala class as a parameter?

Groomed Gorilla I want to pass a Class as a parameter to a Scala function like this: def sampleFunc (c : Class) : List[Any] (Side question: Should the type in the parameter be Class or Class[_]?) The reason I'm passing the Class type is to check if the obje

Pass a Scala class as a parameter?

Groomed Gorilla I want to pass a Class as a parameter to a Scala function like this: def sampleFunc (c : Class) : List[Any] (Side question: Should the type in the parameter be Class or Class[_]?) The reason I'm passing the Class type is to check if the obje

Pass the class name as a parameter

1110101001: I have 3 classes called RedAlert, YellowAlertand BlueAlert. In my class AlertControllerI want a method like this: public void SetAlert(//TAKE IN NAME OF CLASS HERE//) { CLASSNAME anInstance = new CLASSNAME(); } So, for example, I want to: Aler

Pass function as parameter in class

Henry Shackleton I'm having trouble passing a function as an argument to C++. I recreated a minimal working example here: #include <iostream> using namespace std; void print(const double &func(double)) { cout << func(1) << endl; } class Obj { public: d

Pass a Class instance as a parameter

commercial Bank I have a python script with a line that calls a function that exists in another class, the function exists in another script, I have imported the script and access the function, but the function takes a parameter that is an instance of the clas

Pass class type as parameter

belt: Pass type as parameter to api User 872858: You can receive Class as parameter like below, buildCriteriaQ(Class<?> parentClass) { CriteriaBuilder cb = factory.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityClass); R

Pass class type as parameter

belt: Pass type as parameter to api User 872858: You can receive Class as parameter like below, buildCriteriaQ(Class<?> parentClass) { CriteriaBuilder cb = factory.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityClass); R

Pass class type as parameter

belt: Pass type as parameter to api User 872858: You can receive Class as parameter like below, buildCriteriaQ(Class<?> parentClass) { CriteriaBuilder cb = factory.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityClass); R

Pass an array as a parameter to a class

Nick Sims: I'm trying to pass an array as a parameter to another class, but keep getting the error "error: incompatible types: dot cannot be converted to int[]" The first part of my code is: public Circle(int n, int x, int y) { radius = n;

Pass an array as a parameter to a class

Nick Sims: I'm trying to pass an array as a parameter to another class, but keep getting the error "error: incompatible types: dot cannot be converted to int[]" The first part of my code is: public Circle(int n, int x, int y) { radius = n;

Pass a Scala class as a parameter?

Groomed Gorilla I want to pass a Class as a parameter to a Scala function like this: def sampleFunc (c : Class) : List[Any] (Side question: Should the type in the parameter be Class or Class[_]?) The reason I'm passing the Class type is to check if the obje

Pass a class as a function parameter

Alex I am trying to do something like this: function doSomething($param, Class) { Class::someFunction(); } $someVar = doSomething($param, Class); is it possible? To better explain what I'm trying to do. I have a helper function in Laravel to generate unique

Pass the class as a parameter

Vaux I have a form that can be validated. When I instantiate the form, I pass a class as a parameter so I can update the value on that class. Bussines _bussines = new Bussines (); public frmUsuario(Bussines b) { _bussines = b; InitializeComponent(); }

Pass BlocProvider with class parameter

don't stop In a class in my application, I want to BlocProvideruse class parameter passing like: enum MenuItems{ dashboard, tutorials, logout } class DashboardItems { MenuItems menuItem; BlocProvider action; DashboardItems( { @requi

Pass function as parameter in class

Henry Shackleton I'm having trouble passing a function as an argument to C++. I recreated a minimal working example here: #include <iostream> using namespace std; void print(const double &func(double)) { cout << func(1) << endl; } class Obj { public: d

Pass the Child class as a parameter

SAN I have a basic class public abstract class BaseClass { public DateTime CreateTime { get; set; } public string CreateUser { get; set; } } There are few subclasses derived from the base class public class Child1 : BaseClass { } public class Child2

Pass a Scala class as a parameter?

Groomed Gorilla I want to pass a Class as a parameter to a Scala function like this: def sampleFunc (c : Class) : List[Any] (Side question: Should the type in the parameter be Class or Class[_]?) The reason I'm passing the Class type is to check if the obje

Pass the Child class as a parameter

SAN I have a basic class public abstract class BaseClass { public DateTime CreateTime { get; set; } public string CreateUser { get; set; } } There are few subclasses derived from the base class public class Child1 : BaseClass { } public class Child2

Pass parameter as val to class

Marco Prince When declaring a class in Scala, parameters can be defined as valfollows: class MathOperations(val _x: Int, val _y: Int) { var x: Int = _x var y: Int = _y def product = x*y } But in this case, when I omit the valkeyword, instances of the c

Pass the class name as a parameter

1110101001: I have 3 classes called RedAlert, YellowAlertand BlueAlert. In my class AlertControllerI want a method like this: public void SetAlert(//TAKE IN NAME OF CLASS HERE//) { CLASSNAME anInstance = new CLASSNAME(); } So, for example, I want to: Aler

Pass function as parameter in class

Henry Shackleton I'm having trouble passing a function as an argument to C++. I recreated a minimal working example here: #include <iostream> using namespace std; void print(const double &func(double)) { cout << func(1) << endl; } class Obj { public: d