Click here to Skip to main content
15,888,112 members
Home / Discussions / WPF
   

WPF

 
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 
I tried with ObservableCollection also, with ObservableCollection datagrid is filling up a row every time (means the collection is filling up) but the value is not showing up there, can anybody please help me any sort of help.
I have my code in View as below
<Window x:Class="TestWPFApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:local="using:TestWPFApplication">
    <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"/>
        <Button Content="Save" HorizontalAlignment="Left" Margin="180,142,0,0" VerticalAlignment="Top" Width="74" Name="btnSave"
                Command="{Binding Path=TestCommand}"/>
        <Button Content="Save Specific" HorizontalAlignment="Left" Margin="277,142,0,0" VerticalAlignment="Top" Width="74" Name="btnSaveSpecific"
                Command="{Binding Path=TestSpecificCommand}"
                CommandParameter="{Binding ElementName=txtName, Path=Text}" />
        <DataGrid HorizontalAlignment="Left" Margin="103,188,0,0" VerticalAlignment="Top" Height="98" Width="313" 
             IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=DictionaryNames, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                  AutoGenerateColumns="False"  >
            <DataGrid.Columns>
                <DataGridTextColumn Header="Name of Employee" Binding="{Binding Name}" />
            </DataGrid.Columns> 
        </DataGrid>

<pre>
</Grid>



My ViewModel
public class TestViewModel : INotifyPropertyChanged
    {
        TestData _testData;

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

        public TestViewModel()
        {
            _testData = new TestData();

            this.TestCommand = new TestCommand(this);

            this.TestSpecificCommand = new TestSpecificCommand(this);
            _dictionaryNames = new ObservableCollection<String>();
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        ObservableCollection<String> _dictionaryNames;
        public ObservableCollection<String> DictionaryNames
        {
            get { return _dictionaryNames; }
            set { _dictionaryNames = value; NotifyPropertyChanged("DictionaryNames"); }
        }

        public Dictionary<short, String> DictionaryName
        {
            get { return _testData.DictionaryName; }
            set { _testData.DictionaryName = value; NotifyPropertyChanged("DictionaryName"); }
        }        

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

        public void AddAnItem()
        {
            int t ;

            if ((DictionaryName == null) || (DictionaryName.Count()<=0))
                t = 1;
            else
               t = DictionaryName.Max(x => x.Key) + 1;

            DictionaryName.Add((short)t, t.ToString() + "Number");
            NotifyPropertyChanged("DictionaryNames");
        }

        public void AddAnItem(string _name)
        {
            int t;

        if ((DictionaryName == null) || (DictionaryName.Count() <= 0))
                t = 1;
            else
                t = (DictionaryName.Count <= 0) ? 1 : DictionaryName.Max(x => x.Key) + 1;

            DictionaryName.Add(short.Parse(t.ToString()), _name);
            _dictionaryNames.Add(_name);
            NotifyPropertyChanged("DictionaryNames");
        }        
    }
Thanks,

Abdul Aleem

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

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 
AnswerRe: Add a check box and delete multiple rows from DataGrid in WPF Pin
Mycroft Holmes12-May-16 13:06
professionalMycroft Holmes12-May-16 13:06 
GeneralRe: Add a check box and delete multiple rows from DataGrid in WPF Pin
indian14312-May-16 14:12
indian14312-May-16 14:12 
QuestionUse Different Paths In Control Template Pin
Kevin Marois11-May-16 13:14
professionalKevin Marois11-May-16 13:14 
AnswerRe: Use Different Paths In Control Template Pin
Gerry Schmitz11-May-16 16:06
mveGerry Schmitz11-May-16 16:06 
QuestionHandle Title Bar Icon Click Pin
Kevin Marois11-May-16 5:56
professionalKevin Marois11-May-16 5:56 
AnswerRe: Handle Title Bar Icon Click Pin
CHill6011-May-16 22:42
mveCHill6011-May-16 22:42 
AnswerRe: Handle Title Bar Icon Click Pin
Pete O'Hanlon11-May-16 23:50
mvePete O'Hanlon11-May-16 23:50 
Questionwpf Pin
Member 113037949-May-16 7:39
Member 113037949-May-16 7:39 
AnswerRe: wpf Pin
Pete O'Hanlon9-May-16 8:34
mvePete O'Hanlon9-May-16 8:34 
QuestionRe: wpf Pin
ZurdoDev11-May-16 9:20
professionalZurdoDev11-May-16 9:20 
QuestionWPF Dependency Property Of Type UserControl Pin
Kevin Marois3-May-16 5:32
professionalKevin Marois3-May-16 5:32 
QuestionUse TTF Font From Resources Pin
Kevin Marois28-Apr-16 12:13
professionalKevin Marois28-Apr-16 12:13 
AnswerRe: Use TTF Font From Resources Pin
Richard Deeming29-Apr-16 2:18
mveRichard Deeming29-Apr-16 2:18 
GeneralRe: Use TTF Font From Resources Pin
Kevin Marois29-Apr-16 5:21
professionalKevin Marois29-Apr-16 5:21 

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.