CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2007
    Posts
    2

    XAML + WPF namespace

    I have this code:

    <Window x:Class="WpfSimple.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfSimple"
    Title="MainWindow" Height="150" Width="370">
    <Window.DataContext>
    <local:MainWindowViewModel/>
    </Window.DataContext>
    <Grid>
    <Button Name="btnClick"
    Content="Click"
    HorizontalAlignment="Left"
    Height="23"
    Margin="77,45,0,0"
    VerticalAlignment="Top"
    Width="203"
    Command = "{Binding ButtonCommand}"
    CommandParameter="Hai"/>
    </Grid>
    </Window>

    and this namespace class:

    namespace WpfSimple
    {

    //www.codeproject.com/Articles/126249/MVVM-Pattern-in-WPF-A-Simple-Tutorial-for-Absolute

    class MainWindowViewModel
    { .......


    But in the XAML section the tak: <Window.DataContext> told me: the name "MainWindowViewModel" dont exist the namespace "clr-namespace:WpfSimple"


    What can it be?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: XAML + WPF namespace

    Do you have a class called "MainWindowViewModel" that is defined in the WpfSimple namespace?

  3. #3
    Join Date
    May 2007
    Posts
    2

    Re: XAML + WPF namespace

    Yes I have it:

    I read at: http://msdn.microsoft.com/es-es/libr...v=vs.110).aspx : "In order to reference this custom class, you also need to include it as a reference for your current project, which you would typically do using the Solution Explorer UI in Visual Studio."

    But I dont know how to do that.

    namespace WpfSimple
    {

    //www.codeproject.com/Articles/126249/MVVM-Pattern-in-WPF-A-Simple-Tutorial-for-Absolute

    class MainWindowViewModel
    {
    private ICommand m_ButtonCommand;
    public ICommand ButtonCommand
    {
    get
    {
    return m_ButtonCommand;
    }
    set
    {
    m_ButtonCommand = value;
    }
    }

    public MainWindowViewModel()
    {
    ButtonCommand = new RelayCommand(new Action<object>(ShowMessage));
    }

    public void ShowMessage(object obj)
    {

    MessageBox.Show(obj.ToString());
    }
    }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured