Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:07:28+00:00 2026-06-11T22:07:28+00:00

I am trying to learn MVVM by making a magic card app. I don’t

  • 0

I am trying to learn MVVM by making a magic card app. I don’t conceptually know how to link data and commands into the View from the view Model. I understand how to make data available in the view model but not how to access it from the view.

The main question is what is incorrect in the xaml, I am getting an exception on the button, I assume to do with the binding to the command which also means that the data is probably not working either.

<Window x:Class="MagicDB.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MagicDB"
    Title="MainWindow" Width="500" Height="500">

<Window.DataContext>
    <local:MainWindowViewModel x:Name="viewModel" />
</Window.DataContext>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50*" />
        <RowDefinition Height="450*" />
    </Grid.RowDefinitions>
    <DataGrid AutoGenerateColumns="False" 
        HorizontalAlignment="Left" 
        VerticalAlignment="Top"
        IsSynchronizedWithCurrentItem="True" Width="auto" Height="auto" Grid.Row="1">
        <DataGrid.Columns>
            <DataGridTextColumn Header="ID" Binding="{Binding CardID}" Width="25" ></DataGridTextColumn>
            <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="110"></DataGridTextColumn>
            <DataGridTextColumn Header="Mana" Binding="{Binding Mana}" Width="30" ></DataGridTextColumn>
            <DataGridTextColumn Header="Card Text" Binding="{Binding CardTXT}" Width="100*"></DataGridTextColumn>
            <DataGridTextColumn Header="Flavor Text" Binding="{Binding FlavorTXT}" Width="100*"></DataGridTextColumn>
            <!--DataGridCheckBoxColumn Header="Cost" Binding="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" ></DataGridCheckBoxColumn-->
        </DataGrid.Columns>
    </DataGrid>
    <Button Content="Initiliaze Database" Height="23" HorizontalAlignment="Left" Margin="55,16,0,0" Name="initdb" VerticalAlignment="Top" Width="75"
            Command="Binding InitCardDB"/>
</Grid>

The main issue is an exception is thrown on the button. I don’t think I am getting the data for the grid either.

namespace MagicDB
{
class MainWindowViewModel : ObservableObject
{
    private CardDB _cards;
    private Command _InitCardDB;

    public CardDB Cards
    {
        get { return _cards; }
        set { _cards = value; OnPropertyChanged("Cards"); }
    }

   public MainWindowViewModel()
    {
        //var cards = GetCards();

        //var cardViewModels = new List<CardViewModel>();
        //cards.ForEach(c => cardViewModels.Add(new CardViewModel(c)));
        _InitCardDB = new Command(InitDB, true);
        Cards = new CardDB(); ;
    }

    public Command InitCardDB
    {
        get
        {
            if (_InitCardDB == null)
            {
                _InitCardDB = new Command(
                    param => InitDB()
                );
            }
            return _InitCardDB;
        }

    }

    private void InitDB()
    {
        _cards = new CardDB();
        _cards.InitDB();
    }
}

}

Any help would be great, especially what I am doing wrong and where I conceptually made an error. I might be approaching this incorrectly altogether? Thanks in advance for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:07:29+00:00Added an answer on June 11, 2026 at 10:07 pm

    The DataGrid has no items because you need to set its ItemsSource

    The Button is causing an exception because you are attempting to assign the string "Binding InitCardDb" to the Command property instead of using "{Binding InitCardDb}" The "{}" tells the XAML processor to use what’s called a Markup Extension instead of using the text

    Other than that your approach looks correct

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn MVVM, but there is something I don't understand yet. Currently,
Trying to learn MVP pattern with C#... Does anyone know of any particularly good
Trying to learn PL/SQL with multimedia data. Can anyone please point out that from
I'm trying to learn the MVVM pattern. The main problem I'm having is learning
Trying to learn some F# and I've run into a couple of hangups. Here's
I am currently trying to learn how to implement MVVM using Unity and Caliburn
I trying to learn web application development. I'm currently using Google App Engine to
I have been trying to learn MVVM using Laurent Bugnion MVVM light method. I
I'm trying to learn MVVM with Caliburn.Micro. My exercise is to have a view
I'm trying to learn MVVM Light and am looking for a good basic example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.