Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WPF Bindings to MySettings.Default Not Updating When Property Changes (VB.Net)

Posted on 2012-04-03
6
Medium Priority
?
568 Views
Last Modified: 2012-04-04
Hi,

I recently discovered the User Settings functionality of Visual Studio and thought I would give it a try so that my users can customise colours, fonts etc.

While playing to gain familiarity I have created a Setting called 'ButtonColour' as a system.drawing.color and then, in XAML, created a binding to this setting in the Control Template for the Buttons in my project, using an iValueConverter to convert the color to a System.Windows.Media.Brush.

This works as it should.

I then added a ComboBox, which contains all of the non-system KnownColors, and set the SelectionChanged event to update the ButtonColor setting to that selected from the Combo.

My problem is that although ButtonColor setting is changed and saved, the Buttons on the screen using the bound Control Template do not change colour until they are reloaded.

I would have though that MySettings would implement INotifyPropertyChanged, but it seems not - or if it is it is not firing.

What is the 'correct' way to get my buttons to change colour in real-time as the ButtonColor setting changes?

All help appreciated.

Cheers

Sim
0
Comment
Question by:Simon482
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37805405
Does it update if you call InvalidateVisual function on the button?

http://msdn.microsoft.com/en-us/library/system.windows.uielement.invalidatevisual.aspx
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37805417
Are you calling the Save method for the settings?  Nothing will get saved if you don't.

My.Settings.Default.Save()
0
 

Author Comment

by:Simon482
ID: 37805524
Thanks for your replies

@CodeCruiser - I have given this a try and no, I am afraid not.

@TheLearnedOne - Yes, I am saving the change and if I restart the app I can see it has taken effect - I just would like the UI to reflect the changes in real-time.

I have a workaround, but it seems a little convoluted.

I have created a Class name 'ButtonStyle' which inherits from DependencyObject and Implements INotifyPropertyChanged, and then created a dependcyproperty called ColourProperty.

I then bound the ColourProperty to the ButtonColour Setting, and bound my ControlTemplate to the ColourProperty of my new Class.

When I change the color from the Combo I refresh the binding of ColourProperty and this is reflected on the UI instantly.

However, I feel this is all a bit unnecesary and suspect there is an easier way... Opinions?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 37805670
I misunderstood your question.

"I would have though that MySettings would implement INotifyPropertyChanged, but it seems not - or if it is it is not firing."

INotifyPropertyChanged is a new construct, and MySettings is an old one.  I haven't tried extending the Settings class to add new behavior, and I am not sure if there is a reason to want to.  If you look at Aspect Oriented Programming (AOP), and dependency injection, you can add behavior where it didn't exist before.

Introduction to Spring's Aspect Oriented Programming(AOP)
http://www.javabeat.net/articles/51-introduction-to-springs-aspect-oriented-programminga-1.html
0
 

Author Closing Comment

by:Simon482
ID: 37805820
OK, thanks, plenty of further reading there...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37805839
BTW, that was an article that talked about the concepts of AOP, as it was a Java-based implementation.  There are .NET flavors, such as Post Sharp.

AOP on .NET
http://www.sharpcrafters.com/aop.net

An easy way to implement what you want is to use a custom class that implements the INotifyPropertyChanged that you need, and has a persistence mechanism, rather than trying to bend something in that direction.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question