Click here to Skip to main content
15,890,579 members
Home / Discussions / WPF
   

WPF

 
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 
Hi,

My here is my View
<Window x:Class="TestWPFApplication.MainWindow"<br />
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:testns="clr-namespace:TestWPFApplication"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        >
        <Window.Resources><br />
        <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}"  HorizontalAlignment="Left" Height="22" Margin="160,64,0,0" TextWrapping="Wrap" 
                 Name="txtName" VerticalAlignment="Top" Width="120"/>

<pre>
    <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}" />
    <Label Content="Enter Id" HorizontalAlignment="Left" Margin="58,17,0,0" VerticalAlignment="Top" Name="lblId"/>
    <TextBox Text="{Binding Name, Mode=OneWay}"  HorizontalAlignment="Left" Height="22" Margin="160,18,0,0" TextWrapping="Wrap" 
             Name="txtId" VerticalAlignment="Top" Width="120"/>
    <Button Content="Save 2" HorizontalAlignment="Left" Margin="412,142,0,0" VerticalAlignment="Top" Width="74" Name="btnSaveSpecific2"
            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>
</Grid>



And ViewModel
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

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");
            }
        }

        ObservableCollection<TestData> _personNames;
        public ObservableCollection<TestData> PersonNames
        {
            get { return _personNames; }
            set
            {
                _personNames = value; NotifyPropertyChanged("PersonNames"); 
            }
        }

        ObservableCollection<Tuple<int, TestData>> _dictionaryNames;
        ObservableCollection<Tuple<int, TestData>> DictionaryNames
        {
            get { return _dictionaryNames; }
            set
            {
                _dictionaryNames = value; NotifyPropertyChanged("DictionaryNames");
            }
        }     

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {<br />
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
        }

        private ICommand _clickCommand;
        public ICommand ClickCommand
        {
            get
            {
                return _clickCommand ?? (_clickCommand = new TestSpecificCommand(() => AddAnItem(), _canExecute));

            }

        }

        public bool _canExecute { get; set; }
        private int _id;
        public int Id
        {
            get { return _id; }
            set
            {
                _id = value; NotifyPropertyChanged("Id");
            }
        }
        public void AddAnItem()
        {<br />
            _personNames.Add(new TestData(Id, _name));
        }  

        public void AddAnItem(string _name)
        {
            int t;

            if ((_personNames == null) || (_personNames.Count() <= 0))
                t = 1;
            else
                t = (_personNames.Count <= 0) ? 1 : _personNames.Max(x => x.Id) + 1;
            _personNames.Add(new TestData(t, _name));
        }        
    }
}
When I am referencing it, it is saying that the TestViewModel is not present in the clr-namespace:TestWPFApplication namespace and saying the UI above that Invalid Markup, can you please let me know buddy what's wrong in it?
Thanks,

Abdul Aleem

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

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 
QuestionAdd Dictionary in ObsavableCollection Pin
indian14314-May-16 9:20
indian14314-May-16 9:20 
AnswerRe: Add Dictionary in ObsavableCollection Pin
Pete O'Hanlon14-May-16 22:07
mvePete O'Hanlon14-May-16 22:07 
AnswerRe: Add Dictionary in ObsavableCollection Pin
Richard Deeming16-May-16 1:18
mveRichard Deeming16-May-16 1:18 
GeneralRe: Add Dictionary in ObsavableCollection Pin
indian14316-May-16 6:35
indian14316-May-16 6:35 
QuestionDatagrid is not updating the values after changing the collection in the ViewModel in WPF Pin
indian14313-May-16 11:02
indian14313-May-16 11:02 
AnswerRe: Datagrid is not updating the values after changing the collection in the ViewModel in WPF Pin
Richard Deeming13-May-16 11:16
mveRichard Deeming13-May-16 11:16 
GeneralRe: Datagrid is not updating the values after changing the collection in the ViewModel in WPF Pin
indian14313-May-16 11:44
indian14313-May-16 11:44 
GeneralRe: Datagrid is not updating the values after changing the collection in the ViewModel in WPF Pin
indian14313-May-16 21:09
indian14313-May-16 21:09 
GeneralRe: Datagrid is not updating the values after changing the collection in the ViewModel in WPF Pin
Pete O'Hanlon14-May-16 3:39
mvePete O'Hanlon14-May-16 3:39 
QuestionConvert This XAML To C# Pin
Kevin Marois12-May-16 13:45
professionalKevin Marois12-May-16 13:45 
QuestionAdd a check box and delete multiple rows from DataGrid in WPF Pin
indian14312-May-16 8:46
indian14312-May-16 8:46 

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.