Click here to Skip to main content
15,886,362 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Binding the x,y location on a Canvas with a ItemsControl Pin
Pete O'Hanlon25-May-16 0:56
mvePete O'Hanlon25-May-16 0:56 
GeneralRe: Binding the x,y location on a Canvas with a ItemsControl Pin
Meshack Musundi25-May-16 1:27
professionalMeshack Musundi25-May-16 1:27 
QuestionRe: Binding the x,y location on a Canvas with a ItemsControl Pin
Kenneth Haugland7-Jun-16 20:22
mvaKenneth Haugland7-Jun-16 20:22 
GeneralRe: Binding the x,y location on a Canvas with a ItemsControl Pin
Meshack Musundi8-Jun-16 10:27
professionalMeshack Musundi8-Jun-16 10:27 
GeneralRe: Binding the x,y location on a Canvas with a ItemsControl Pin
Kenneth Haugland8-Jun-16 10:41
mvaKenneth Haugland8-Jun-16 10:41 
QuestionGet Datagrid Selected cell value in ViewModel Pin
indian14315-May-16 12:48
indian14315-May-16 12:48 
AnswerRe: Get Datagrid Selected cell value in ViewModel Pin
Pete O'Hanlon15-May-16 23:26
mvePete O'Hanlon15-May-16 23:26 
QuestionAdding Resources is giving errors not letting me add Resources Pin
indian14315-May-16 2:48
indian14315-May-16 2:48 
Hi All,

I have a WPF application named : TestWPFApplication, In that I have folders View and View Model. I have View class as below
namespace TestWPFApplication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        TestViewModel _testViewModel;
        public MainWindow()
        {
            InitializeComponent();
            _testViewModel = new TestViewModel();
            DataContext = _testViewModel;            
        }      
    }
}
then I have ViewModel class as below.
namespace TestWPFApplication
{
    public class TestViewModel : INotifyPropertyChanged
    {
        TestData _testData;

        //public TestCommand TestCommand { get; set; }
        public TestSpecificCommand TestSpecificCommand { get; set; }

        public TestViewModel()
        {
            _testData = new TestData();
            _personNames = new ObservableCollection<TestData>();
            //_dictionaryNames = new ObservableCollection<Tuple<int, TestData>>();

            //this.TestCommand = new TestCommand(this);
            this.TestSpecificCommand = new TestSpecificCommand(this);
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value; NotifyPropertyChanged("Name");
            }
        }

        private int _id;
        public int Id
        {
            get { return _id; }
            set
            {
                _id = value; NotifyPropertyChanged("Id");
            }
        }
}}
When I am trying to reference this ViewModel as static resource to bind properties of ViewModel to View then its giving error as below.
<Window x:Class="TestWPFApplication.MainWindow"
         xmlns:testns="clr-namespace:TestWPFApplication;assembly=TestWPFApplication"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        >
    <Window.Resources>
        <testns:TestViewModel x:Key="_testViewModel" Name="Abdul">
        </testns:TestViewModel>
    </Window.Resources>
    <Grid>
        <Label Content="Enter Name" HorizontalAlignment="Left" Margin="58,62,0,0" VerticalAlignment="Top" Name="lblName"/>
        <TextBox Text="{Binding Name, Mode=OneWay, Source={StaticResource _testViewModel}}"  HorizontalAlignment="Left" Height="22" Margin="160,64,0,0" TextWrapping="Wrap" 
                 Name="txtName" VerticalAlignment="Top" Width="120"/>
        <Label Content="Enter Id" HorizontalAlignment="Left" Margin="58,17,0,0" VerticalAlignment="Top" Name="lblId"/>
        <TextBox Text="{Binding Name, Mode=OneWay, Source={StaticResource _testViewModel}}"  HorizontalAlignment="Left" Height="22" Margin="160,18,0,0" TextWrapping="Wrap" 
                 Name="txtId" VerticalAlignment="Top" Width="120"/>
        <!--<Button Content="Save" HorizontalAlignment="Left" Margin="277,142,0,0" VerticalAlignment="Top" Width="74" Name="btnSaveSpecific"
                Command="{Binding Path=TestSpecificCommand}"
                CommandParameter="{Binding ElementName=txtName, Path=Text}" />-->
        <Button Content="Save" HorizontalAlignment="Left" Margin="277,142,0,0" VerticalAlignment="Top" Width="74" Name="btnSaveSpecific"
                Command="{Binding Path=ClickCommand}"
                />
        <DataGrid HorizontalAlignment="Left" Margin="103,188,0,0" VerticalAlignment="Top" Height="98" Width="313" 
            IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=PersonNames, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                  AutoGenerateColumns="False"  >
            <DataGrid.Columns>
                <DataGridTextColumn Header="Name of Employee" Binding="{Binding Path=Name}" />
            </DataGrid.Columns> 
        </DataGrid>

<pre>
</Grid>



And error is as below
Error   1   The tag 'TestViewModel' does not exist in XML namespace 'clr-namespace:TestWPFApplication;assembly=TestWPFApplication'. Line 8 Position 10. \\VBOXSVR\VMShared\Test Projects\TestWPFApplication\TestWPFApplication\View\MainWindow.xaml 8   10  TestWPFApplication
Error   2   The name "TestViewModel" does not exist in the namespace "clr-namespace:TestWPFApplication;assembly=TestWPFApplication".    \\VBOXSVR\VMShared\Test Projects\TestWPFApplication\TestWPFApplication\View\MainWindow.xaml 8   9   TestWPFApplication
Error   3   The type 'testns:TestViewModel' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.    \\VBOXSVR\VMShared\Test Projects\TestWPFApplication\TestWPFApplication\View\MainWindow.xaml 8   10  TestWPFApplication
<pre>
Any help please? I am not able to understand this, I have ViewModel in the same assembly as View and then I try to reference them using the same Assembly name and Name space name it says the ViewModel class is not available.

Any help is appreciated please help me.

<div class="signature">Thanks,

Abdul Aleem

"There is already enough hatred in the world lets spread love, compassion and affection."</div>

AnswerRe: Adding Resources is giving errors not letting me add Resources Pin
Richard Deeming16-May-16 1:21
mveRichard Deeming16-May-16 1:21 
GeneralRe: Adding Resources is giving errors not letting me add Resources Pin
indian14316-May-16 6:25
indian14316-May-16 6:25 
GeneralRe: Adding Resources is giving errors not letting me add Resources Pin
Richard Deeming16-May-16 6:28
mveRichard Deeming16-May-16 6:28 
GeneralRe: Adding Resources is giving errors not letting me add Resources Pin
indian14316-May-16 6:36
indian14316-May-16 6:36 
GeneralRe: Adding Resources is giving errors not letting me add Resources Pin
indian14316-May-16 14:03
indian14316-May-16 14:03 
GeneralRe: Adding Resources is giving errors not letting me add Resources Pin
Richard Deeming17-May-16 1:02
mveRichard Deeming17-May-16 1:02 
QuestionPassing two parameters in Command biding in WPF and MVVM Pin
indian14315-May-16 1:27
indian14315-May-16 1:27 
AnswerRe: Passing two parameters in Command biding in WPF and MVVM Pin
Pete O'Hanlon15-May-16 8:15
mvePete O'Hanlon15-May-16 8:15 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
indian14315-May-16 12:40
indian14315-May-16 12:40 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
Pete O'Hanlon15-May-16 19:33
mvePete O'Hanlon15-May-16 19:33 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
indian14316-May-16 6:32
indian14316-May-16 6:32 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
Pete O'Hanlon16-May-16 7:05
mvePete O'Hanlon16-May-16 7:05 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
indian14316-May-16 14:39
indian14316-May-16 14:39 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
Pete O'Hanlon16-May-16 20:47
mvePete O'Hanlon16-May-16 20:47 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
indian14316-May-16 22:08
indian14316-May-16 22:08 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
Pete O'Hanlon16-May-16 22:11
mvePete O'Hanlon16-May-16 22:11 
GeneralRe: Passing two parameters in Command biding in WPF and MVVM Pin
Meshack Musundi23-May-16 3:12
professionalMeshack Musundi23-May-16 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.