C# - Xamarin.Forms - Dependency Service and event
I would like to be notified with a PropertyChanged event raised from a class MyClass
implementing an interface IMyInterface
. The instance of this class is retrieved with DependencyService.Get<IMyInterface>();
Now, this is the class (Android project), in which there is a property with a backing field:
class MyClass : IMyInterface {
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
private set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void OnSomethingHappens() { //This method is called when something particular happens
/* Some code... */
IsEnabled = true; //The point where the property is changed
/* ...some other code */
}
}
The interface (Forms project) looks like this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
This interface is implementing INotifyPropertyChanged
in order to have the possibility to listen to a property change (as seen in the class above). So far, so good.
The problem is when, in my Forms project, I register an event handler with this:
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
But when the property in my implementing class changes, PropertyChanged
results null, and this means that the event is never fired.
I would like to add a little thing: recently, I experienced that accessing a non-static list property with DependencyService.Get<IMyInterface>().MyList
was useless, since MyList
resulted to be of size 0
, even if this list was filled inside the implementing class. I solved this using a static property. Maybe this is related to the issue above.
I would like to understand what I am mistaking in order to have this PropertyChanged
event working correctly.
c# events xamarin.forms xamarin.android
add a comment |
I would like to be notified with a PropertyChanged event raised from a class MyClass
implementing an interface IMyInterface
. The instance of this class is retrieved with DependencyService.Get<IMyInterface>();
Now, this is the class (Android project), in which there is a property with a backing field:
class MyClass : IMyInterface {
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
private set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void OnSomethingHappens() { //This method is called when something particular happens
/* Some code... */
IsEnabled = true; //The point where the property is changed
/* ...some other code */
}
}
The interface (Forms project) looks like this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
This interface is implementing INotifyPropertyChanged
in order to have the possibility to listen to a property change (as seen in the class above). So far, so good.
The problem is when, in my Forms project, I register an event handler with this:
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
But when the property in my implementing class changes, PropertyChanged
results null, and this means that the event is never fired.
I would like to add a little thing: recently, I experienced that accessing a non-static list property with DependencyService.Get<IMyInterface>().MyList
was useless, since MyList
resulted to be of size 0
, even if this list was filled inside the implementing class. I solved this using a static property. Maybe this is related to the issue above.
I would like to understand what I am mistaking in order to have this PropertyChanged
event working correctly.
c# events xamarin.forms xamarin.android
Are you sure you're accessing the same instance of_myService
, each call to the dependency service is returning a new instance, not a singleton.
– JSteward
Nov 20 '18 at 21:55
It's what I thought when I encountered that issue with theList
. Anyway, now I have only one reference to the impementing class. Maybe I should always callDependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?
– Kenna
Nov 20 '18 at 22:00
What I would suggest you create a static instance of your dependency callDependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.
– G.hakim
Nov 21 '18 at 6:52
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, butPropertyChanged
is always null.
– Kenna
Nov 21 '18 at 8:38
add a comment |
I would like to be notified with a PropertyChanged event raised from a class MyClass
implementing an interface IMyInterface
. The instance of this class is retrieved with DependencyService.Get<IMyInterface>();
Now, this is the class (Android project), in which there is a property with a backing field:
class MyClass : IMyInterface {
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
private set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void OnSomethingHappens() { //This method is called when something particular happens
/* Some code... */
IsEnabled = true; //The point where the property is changed
/* ...some other code */
}
}
The interface (Forms project) looks like this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
This interface is implementing INotifyPropertyChanged
in order to have the possibility to listen to a property change (as seen in the class above). So far, so good.
The problem is when, in my Forms project, I register an event handler with this:
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
But when the property in my implementing class changes, PropertyChanged
results null, and this means that the event is never fired.
I would like to add a little thing: recently, I experienced that accessing a non-static list property with DependencyService.Get<IMyInterface>().MyList
was useless, since MyList
resulted to be of size 0
, even if this list was filled inside the implementing class. I solved this using a static property. Maybe this is related to the issue above.
I would like to understand what I am mistaking in order to have this PropertyChanged
event working correctly.
c# events xamarin.forms xamarin.android
I would like to be notified with a PropertyChanged event raised from a class MyClass
implementing an interface IMyInterface
. The instance of this class is retrieved with DependencyService.Get<IMyInterface>();
Now, this is the class (Android project), in which there is a property with a backing field:
class MyClass : IMyInterface {
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
private set { _isEnabled = value; OnPropertyChanged("IsEnabled"); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void OnSomethingHappens() { //This method is called when something particular happens
/* Some code... */
IsEnabled = true; //The point where the property is changed
/* ...some other code */
}
}
The interface (Forms project) looks like this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
This interface is implementing INotifyPropertyChanged
in order to have the possibility to listen to a property change (as seen in the class above). So far, so good.
The problem is when, in my Forms project, I register an event handler with this:
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
But when the property in my implementing class changes, PropertyChanged
results null, and this means that the event is never fired.
I would like to add a little thing: recently, I experienced that accessing a non-static list property with DependencyService.Get<IMyInterface>().MyList
was useless, since MyList
resulted to be of size 0
, even if this list was filled inside the implementing class. I solved this using a static property. Maybe this is related to the issue above.
I would like to understand what I am mistaking in order to have this PropertyChanged
event working correctly.
c# events xamarin.forms xamarin.android
c# events xamarin.forms xamarin.android
asked Nov 20 '18 at 21:49
KennaKenna
3717
3717
Are you sure you're accessing the same instance of_myService
, each call to the dependency service is returning a new instance, not a singleton.
– JSteward
Nov 20 '18 at 21:55
It's what I thought when I encountered that issue with theList
. Anyway, now I have only one reference to the impementing class. Maybe I should always callDependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?
– Kenna
Nov 20 '18 at 22:00
What I would suggest you create a static instance of your dependency callDependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.
– G.hakim
Nov 21 '18 at 6:52
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, butPropertyChanged
is always null.
– Kenna
Nov 21 '18 at 8:38
add a comment |
Are you sure you're accessing the same instance of_myService
, each call to the dependency service is returning a new instance, not a singleton.
– JSteward
Nov 20 '18 at 21:55
It's what I thought when I encountered that issue with theList
. Anyway, now I have only one reference to the impementing class. Maybe I should always callDependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?
– Kenna
Nov 20 '18 at 22:00
What I would suggest you create a static instance of your dependency callDependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.
– G.hakim
Nov 21 '18 at 6:52
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, butPropertyChanged
is always null.
– Kenna
Nov 21 '18 at 8:38
Are you sure you're accessing the same instance of
_myService
, each call to the dependency service is returning a new instance, not a singleton.– JSteward
Nov 20 '18 at 21:55
Are you sure you're accessing the same instance of
_myService
, each call to the dependency service is returning a new instance, not a singleton.– JSteward
Nov 20 '18 at 21:55
It's what I thought when I encountered that issue with the
List
. Anyway, now I have only one reference to the impementing class. Maybe I should always call DependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?– Kenna
Nov 20 '18 at 22:00
It's what I thought when I encountered that issue with the
List
. Anyway, now I have only one reference to the impementing class. Maybe I should always call DependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?– Kenna
Nov 20 '18 at 22:00
What I would suggest you create a static instance of your dependency call
DependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.– G.hakim
Nov 21 '18 at 6:52
What I would suggest you create a static instance of your dependency call
DependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.– G.hakim
Nov 21 '18 at 6:52
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, but
PropertyChanged
is always null.– Kenna
Nov 21 '18 at 8:38
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, but
PropertyChanged
is always null.– Kenna
Nov 21 '18 at 8:38
add a comment |
1 Answer
1
active
oldest
votes
Ok, I figured out how to solve this.
Basically, I created a property with a private static event
backing field, as follows:
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
This way, I could have the following code working properly:
protected void OnPropertyChanged(string name)
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Infact, _propertyChanged
was not null
anymore, since I subscribed to the event with the following code (formally identical to the one posted on my question, with the difference that I used the PropertyChanged
property backed with the private static field _propertyChanged
):
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
Now I think that this was necessary because I am using DependencyService
, otherwise, in normal code, this issue should not come out.
Anyway, I am guessing if the idea of having a EventHandler
property backed with a private static event
field is a good code practice or just sounds weird. But it works, and it works pretty good.
But, in order to do all of this, I had to change this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
to this:
public interface IMyInterface
{
PropertyChangedEventHandler PropertyChanged { get; set; }
/* code relating the interface */
}
I had to add that property in IMyInterface
so that I could access it from my Forms project code.
Moreover, I no more implement INotifyPropertyChanged
, because INotifyPropertyChanged
asks me to implement the interface with a:
public event PropertyChangedEventHandler PropertyChanged
inside my implementing class, but I substituted it with
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
as I exposed above.
And, by the way, I also changed my private bool field_isEnabled
(see above in my question) to bestatic
since callingDependencyService.Get<IMyInterface>().IsEnabled
returned mefalse
even if the backing field had changed, but now, with static modifier,DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.
– Kenna
Nov 21 '18 at 10:01
add a 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',
autoActivateHeartbeat: false,
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%2f53402103%2fc-sharp-xamarin-forms-dependency-service-and-event%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
Ok, I figured out how to solve this.
Basically, I created a property with a private static event
backing field, as follows:
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
This way, I could have the following code working properly:
protected void OnPropertyChanged(string name)
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Infact, _propertyChanged
was not null
anymore, since I subscribed to the event with the following code (formally identical to the one posted on my question, with the difference that I used the PropertyChanged
property backed with the private static field _propertyChanged
):
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
Now I think that this was necessary because I am using DependencyService
, otherwise, in normal code, this issue should not come out.
Anyway, I am guessing if the idea of having a EventHandler
property backed with a private static event
field is a good code practice or just sounds weird. But it works, and it works pretty good.
But, in order to do all of this, I had to change this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
to this:
public interface IMyInterface
{
PropertyChangedEventHandler PropertyChanged { get; set; }
/* code relating the interface */
}
I had to add that property in IMyInterface
so that I could access it from my Forms project code.
Moreover, I no more implement INotifyPropertyChanged
, because INotifyPropertyChanged
asks me to implement the interface with a:
public event PropertyChangedEventHandler PropertyChanged
inside my implementing class, but I substituted it with
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
as I exposed above.
And, by the way, I also changed my private bool field_isEnabled
(see above in my question) to bestatic
since callingDependencyService.Get<IMyInterface>().IsEnabled
returned mefalse
even if the backing field had changed, but now, with static modifier,DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.
– Kenna
Nov 21 '18 at 10:01
add a comment |
Ok, I figured out how to solve this.
Basically, I created a property with a private static event
backing field, as follows:
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
This way, I could have the following code working properly:
protected void OnPropertyChanged(string name)
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Infact, _propertyChanged
was not null
anymore, since I subscribed to the event with the following code (formally identical to the one posted on my question, with the difference that I used the PropertyChanged
property backed with the private static field _propertyChanged
):
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
Now I think that this was necessary because I am using DependencyService
, otherwise, in normal code, this issue should not come out.
Anyway, I am guessing if the idea of having a EventHandler
property backed with a private static event
field is a good code practice or just sounds weird. But it works, and it works pretty good.
But, in order to do all of this, I had to change this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
to this:
public interface IMyInterface
{
PropertyChangedEventHandler PropertyChanged { get; set; }
/* code relating the interface */
}
I had to add that property in IMyInterface
so that I could access it from my Forms project code.
Moreover, I no more implement INotifyPropertyChanged
, because INotifyPropertyChanged
asks me to implement the interface with a:
public event PropertyChangedEventHandler PropertyChanged
inside my implementing class, but I substituted it with
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
as I exposed above.
And, by the way, I also changed my private bool field_isEnabled
(see above in my question) to bestatic
since callingDependencyService.Get<IMyInterface>().IsEnabled
returned mefalse
even if the backing field had changed, but now, with static modifier,DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.
– Kenna
Nov 21 '18 at 10:01
add a comment |
Ok, I figured out how to solve this.
Basically, I created a property with a private static event
backing field, as follows:
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
This way, I could have the following code working properly:
protected void OnPropertyChanged(string name)
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Infact, _propertyChanged
was not null
anymore, since I subscribed to the event with the following code (formally identical to the one posted on my question, with the difference that I used the PropertyChanged
property backed with the private static field _propertyChanged
):
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
Now I think that this was necessary because I am using DependencyService
, otherwise, in normal code, this issue should not come out.
Anyway, I am guessing if the idea of having a EventHandler
property backed with a private static event
field is a good code practice or just sounds weird. But it works, and it works pretty good.
But, in order to do all of this, I had to change this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
to this:
public interface IMyInterface
{
PropertyChangedEventHandler PropertyChanged { get; set; }
/* code relating the interface */
}
I had to add that property in IMyInterface
so that I could access it from my Forms project code.
Moreover, I no more implement INotifyPropertyChanged
, because INotifyPropertyChanged
asks me to implement the interface with a:
public event PropertyChangedEventHandler PropertyChanged
inside my implementing class, but I substituted it with
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
as I exposed above.
Ok, I figured out how to solve this.
Basically, I created a property with a private static event
backing field, as follows:
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
This way, I could have the following code working properly:
protected void OnPropertyChanged(string name)
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
Infact, _propertyChanged
was not null
anymore, since I subscribed to the event with the following code (formally identical to the one posted on my question, with the difference that I used the PropertyChanged
property backed with the private static field _propertyChanged
):
_myService = DependencyService.Get<IMyInterface>();
_myService.PropertyChanged += (sender, e) => { /* do stuff */ };
Now I think that this was necessary because I am using DependencyService
, otherwise, in normal code, this issue should not come out.
Anyway, I am guessing if the idea of having a EventHandler
property backed with a private static event
field is a good code practice or just sounds weird. But it works, and it works pretty good.
But, in order to do all of this, I had to change this:
public interface IMyInterface : INotifyPropertyChanged
{
/* code relating the interface */
}
to this:
public interface IMyInterface
{
PropertyChangedEventHandler PropertyChanged { get; set; }
/* code relating the interface */
}
I had to add that property in IMyInterface
so that I could access it from my Forms project code.
Moreover, I no more implement INotifyPropertyChanged
, because INotifyPropertyChanged
asks me to implement the interface with a:
public event PropertyChangedEventHandler PropertyChanged
inside my implementing class, but I substituted it with
private static event PropertyChangedEventHandler _propertyChanged;
public PropertyChangedEventHandler PropertyChanged
{
get { return _propertyChanged; }
set { _propertyChanged = value; }
}
as I exposed above.
answered Nov 21 '18 at 9:56
KennaKenna
3717
3717
And, by the way, I also changed my private bool field_isEnabled
(see above in my question) to bestatic
since callingDependencyService.Get<IMyInterface>().IsEnabled
returned mefalse
even if the backing field had changed, but now, with static modifier,DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.
– Kenna
Nov 21 '18 at 10:01
add a comment |
And, by the way, I also changed my private bool field_isEnabled
(see above in my question) to bestatic
since callingDependencyService.Get<IMyInterface>().IsEnabled
returned mefalse
even if the backing field had changed, but now, with static modifier,DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.
– Kenna
Nov 21 '18 at 10:01
And, by the way, I also changed my private bool field
_isEnabled
(see above in my question) to be static
since calling DependencyService.Get<IMyInterface>().IsEnabled
returned me false
even if the backing field had changed, but now, with static modifier, DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.– Kenna
Nov 21 '18 at 10:01
And, by the way, I also changed my private bool field
_isEnabled
(see above in my question) to be static
since calling DependencyService.Get<IMyInterface>().IsEnabled
returned me false
even if the backing field had changed, but now, with static modifier, DependencyService.Get<IMyInterface>().IsEnabled
returns the correct value.– Kenna
Nov 21 '18 at 10:01
add a 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.
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%2f53402103%2fc-sharp-xamarin-forms-dependency-service-and-event%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
Are you sure you're accessing the same instance of
_myService
, each call to the dependency service is returning a new instance, not a singleton.– JSteward
Nov 20 '18 at 21:55
It's what I thought when I encountered that issue with the
List
. Anyway, now I have only one reference to the impementing class. Maybe I should always callDependencyService.Get<IMyInterface>()
instead (actually, I don't think so)?– Kenna
Nov 20 '18 at 22:00
What I would suggest you create a static instance of your dependency call
DependencyService.Get<IMyInterface>();
and use the same instance everytime you need it anywhere this should solve the issue that you currently have.– G.hakim
Nov 21 '18 at 6:52
Thank you for your reply. I tried using this, but the issue remains. I'm sure that the event subscription is made before the event occurs, but
PropertyChanged
is always null.– Kenna
Nov 21 '18 at 8:38