-
September 30th, 2014, 02:41 PM
#1
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?
-
September 30th, 2014, 03:32 PM
#2
Re: XAML + WPF namespace
Do you have a class called "MainWindowViewModel" that is defined in the WpfSimple namespace?
-
September 30th, 2014, 04:36 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|