Property change notification for struct property, DataGrid, Binding, INotifyPropertyChanged, List's row value...
up vote
0
down vote
favorite
I have a struct
name datapoints which have the property (int x and string y) and the constructor takes a intger and a string to assign their value. I have also made a observablecollection
of that struct datapoints. While making a collection i have passed string property FirstCell and SecondCell in first and second list and this FirstCell and SecondCell are the property which have Inotifyproperty change implemented. Now when i change this FirstCell and SecondCell they do not get changed in the datagrid.
Below is my code for MainWindow.xaml.cs file
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
This is my XAML file
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
Current output is like this
I checked if the InotifyPropertychanged is implemented or not checking their value in the label below and it updates accordingly but the datagrid doesnot update. For example if i change the value of luffy and write Zoro in the first textbox then the first label in output (The First Cell Value(Y1 in DataGrid is):Zoro but the output in the Y table first row is still LUFFY.
P.S- I am writing this program to imitate my situation when i am trying to use datapoints from the OxyPlot so I must use struct and cannot use class for datapoints.
wpf data-binding datagrid observablecollection inotifypropertychanged
add a comment |
up vote
0
down vote
favorite
I have a struct
name datapoints which have the property (int x and string y) and the constructor takes a intger and a string to assign their value. I have also made a observablecollection
of that struct datapoints. While making a collection i have passed string property FirstCell and SecondCell in first and second list and this FirstCell and SecondCell are the property which have Inotifyproperty change implemented. Now when i change this FirstCell and SecondCell they do not get changed in the datagrid.
Below is my code for MainWindow.xaml.cs file
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
This is my XAML file
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
Current output is like this
I checked if the InotifyPropertychanged is implemented or not checking their value in the label below and it updates accordingly but the datagrid doesnot update. For example if i change the value of luffy and write Zoro in the first textbox then the first label in output (The First Cell Value(Y1 in DataGrid is):Zoro but the output in the Y table first row is still LUFFY.
P.S- I am writing this program to imitate my situation when i am trying to use datapoints from the OxyPlot so I must use struct and cannot use class for datapoints.
wpf data-binding datagrid observablecollection inotifypropertychanged
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a struct
name datapoints which have the property (int x and string y) and the constructor takes a intger and a string to assign their value. I have also made a observablecollection
of that struct datapoints. While making a collection i have passed string property FirstCell and SecondCell in first and second list and this FirstCell and SecondCell are the property which have Inotifyproperty change implemented. Now when i change this FirstCell and SecondCell they do not get changed in the datagrid.
Below is my code for MainWindow.xaml.cs file
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
This is my XAML file
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
Current output is like this
I checked if the InotifyPropertychanged is implemented or not checking their value in the label below and it updates accordingly but the datagrid doesnot update. For example if i change the value of luffy and write Zoro in the first textbox then the first label in output (The First Cell Value(Y1 in DataGrid is):Zoro but the output in the Y table first row is still LUFFY.
P.S- I am writing this program to imitate my situation when i am trying to use datapoints from the OxyPlot so I must use struct and cannot use class for datapoints.
wpf data-binding datagrid observablecollection inotifypropertychanged
I have a struct
name datapoints which have the property (int x and string y) and the constructor takes a intger and a string to assign their value. I have also made a observablecollection
of that struct datapoints. While making a collection i have passed string property FirstCell and SecondCell in first and second list and this FirstCell and SecondCell are the property which have Inotifyproperty change implemented. Now when i change this FirstCell and SecondCell they do not get changed in the datagrid.
Below is my code for MainWindow.xaml.cs file
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
This is my XAML file
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
Current output is like this
I checked if the InotifyPropertychanged is implemented or not checking their value in the label below and it updates accordingly but the datagrid doesnot update. For example if i change the value of luffy and write Zoro in the first textbox then the first label in output (The First Cell Value(Y1 in DataGrid is):Zoro but the output in the Y table first row is still LUFFY.
P.S- I am writing this program to imitate my situation when i am trying to use datapoints from the OxyPlot so I must use struct and cannot use class for datapoints.
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
public partial class MainWindow : Window,INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell="LUFFY";
private string _SecondCell= "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X,string Y)
{
x = X;
y = Y;
}
}
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
<Window x:Class="InotifyClassPropInsideList.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:InotifyClassPropInsideList"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="400">
<StackPanel>
<TextBox Text="{Binding FirstCell}" Margin="10"/>
<TextBox Text="{Binding SecondCell}" Margin="10"/>
<StackPanel Orientation="Horizontal">
<Label Content="The First Cell Value (Y1 in DataGrid) is : "/>
<Label Content="{ Binding FirstCell}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="The Second Cell Value is (Y2 in DataGrid) : "/>
<Label Content="{ Binding SecondCell}"/>
</StackPanel>
<Button Content="Button" Margin="50"/>
<DataGrid SelectedIndex="{Binding SelectedDataIndex, Mode=TwoWay}"
ItemsSource="{Binding CheckNotifyUpdate }" AutoGenerateColumns="True"
HorizontalAlignment="Center"></DataGrid>
</StackPanel>
</Window>
wpf data-binding datagrid observablecollection inotifypropertychanged
wpf data-binding datagrid observablecollection inotifypropertychanged
asked Nov 22 at 16:43
mechbaral
224
224
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I changed the struct to class and everything work, but since your data comes by struct I think the below solution will for you.
Struct is a value type and binding will obtain a copy of it hence never update original object.
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell = "LUFFY";
private string _SecondCell = "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
RefreshGrid();
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
RefreshGrid();
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
RefreshGrid();
}
private void RefreshGrid()
{
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X, string Y)
{
x = X;
y = Y;
}
}
Change it to create the Collection every time when there is a change in cell value.
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435264%2fproperty-change-notification-for-struct-property-datagrid-binding-inotifyprop%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I changed the struct to class and everything work, but since your data comes by struct I think the below solution will for you.
Struct is a value type and binding will obtain a copy of it hence never update original object.
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell = "LUFFY";
private string _SecondCell = "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
RefreshGrid();
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
RefreshGrid();
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
RefreshGrid();
}
private void RefreshGrid()
{
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X, string Y)
{
x = X;
y = Y;
}
}
Change it to create the Collection every time when there is a change in cell value.
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
|
show 1 more comment
up vote
1
down vote
accepted
I changed the struct to class and everything work, but since your data comes by struct I think the below solution will for you.
Struct is a value type and binding will obtain a copy of it hence never update original object.
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell = "LUFFY";
private string _SecondCell = "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
RefreshGrid();
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
RefreshGrid();
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
RefreshGrid();
}
private void RefreshGrid()
{
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X, string Y)
{
x = X;
y = Y;
}
}
Change it to create the Collection every time when there is a change in cell value.
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
|
show 1 more comment
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I changed the struct to class and everything work, but since your data comes by struct I think the below solution will for you.
Struct is a value type and binding will obtain a copy of it hence never update original object.
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell = "LUFFY";
private string _SecondCell = "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
RefreshGrid();
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
RefreshGrid();
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
RefreshGrid();
}
private void RefreshGrid()
{
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X, string Y)
{
x = X;
y = Y;
}
}
Change it to create the Collection every time when there is a change in cell value.
I changed the struct to class and everything work, but since your data comes by struct I think the below solution will for you.
Struct is a value type and binding will obtain a copy of it hence never update original object.
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };
private string _FirstCell = "LUFFY";
private string _SecondCell = "SANJI";
public string FirstCell
{
get { return _FirstCell; }
set
{
_FirstCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(FirstCell)));
RefreshGrid();
}
}
public string SecondCell
{
get { return _SecondCell; }
set
{
_SecondCell = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(SecondCell)));
RefreshGrid();
}
}
private ObservableCollection<datapoints> _CheckNotifyUpdate;
public ObservableCollection<datapoints> CheckNotifyUpdate
{
get { return _CheckNotifyUpdate; }
set
{
_CheckNotifyUpdate = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(CheckNotifyUpdate)));
}
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
RefreshGrid();
}
private void RefreshGrid()
{
CheckNotifyUpdate = new ObservableCollection<datapoints>
{
new datapoints(1, FirstCell),
new datapoints(2, SecondCell)
};
}
}
public struct datapoints
{
public int x { get; set; }
public string y { get; set; }
public datapoints(int X, string Y)
{
x = X;
y = Y;
}
}
Change it to create the Collection every time when there is a change in cell value.
edited Nov 23 at 3:44
answered Nov 22 at 17:37
Satish Pai
521410
521410
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
|
show 1 more comment
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
Sorry for late reply, May be i got it wrong but every time I change the value in the textbox it again retains its original value to (LUFFY). And i don't know if the property change is called or not. All i am adding in the code you wrote was the struct datapoints in .cs file. It still does not work :(
– mechbaral
Nov 23 at 1:52
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
@mechbaral have you implemented the xaml as well since there is small change. For example intsead of First cell, it is First row.y.
– Satish Pai
Nov 23 at 2:07
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
Yes I have used the exact xaml that you posted. Actually when I change the value in textbox and click awa, the value in textbox immediately retains its original assigned value i.e. in our case LUFFY
– mechbaral
Nov 23 at 3:13
1
1
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
@mechbaral I have changed the code now, check it out.
– Satish Pai
Nov 23 at 3:56
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
I am really grateful for your help, Have a nice day :D
– mechbaral
Nov 23 at 4:15
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435264%2fproperty-change-notification-for-struct-property-datagrid-binding-inotifyprop%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown