Binding to visible property - is this a bug?

T

Terry

Hi,
I have a couple of labels on a form and their visible property is bound
to boolean properties on a custom object. When I first load the form, all
works as it should. This form is 'tied' together with a search form, and the
user can go back and forth. When the user hits ok, the form is hidden and
the search form is shown and visa-versa. The problem is that when the form
is hidden when the labels visible property is False, and then shown again
with an object that should cause one or more of them to be visible, they are
not! It seems that the framework decides at 'show' time that since the label
is not visible, it no longer has to 'obey' the binding rules for it. This
seems like a bug to me. Of course I can get around the problem by setting
both labels visible property to true in the forms activated event, right
before I bind the newly selected object to the bindidng source. But again,
why are the binding rules changing at show time, they should of been 'fixed'
at load time!
 
L

Linda Liu[MSFT]

Hi Terry,

Firstly, make sure that the Visible property of the Label is set to true
before it is bound to the custom object.

If a control is not visible before it is bound to a data source, the data
binding won't push data from the data source into the control. This is a by
design behavior.

Secondly, you need implement the INotifyPropertyChanged interface for the
custom object, so that when the values of the properties in the custom
object change, the bound control will reflect the change immediately.

The following is a sample:

using System.ComponentModel;

public class Address:INotifyPropertyChanged
{
bool visible;
public bool Visible
{
get { return visible; }
set
{
if (visible != value)
{
visible = value;
OnPropertyChanged("Visible");
}
}
}

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

Please try my suggestion to see if the problem is solved and let me know
the result.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

Terry

Hi Linda and thanks for the responce - even if it was in C#! lol

Not sure you understand what I am trying to say. The program works fine if
I never hide it and then show it again. If I switch the datasource (for the
bindingsource) the visible properties all work ok. I can go from one that
has them 'off' to one that has them 'on' and visa-versa and all is ok. But
if I hide the form while they are 'off' and then reshow the form - it no
longer works. And my question is why? To me, hiding and re-showing a form
should not change the behavior of the form! It is like the framework is
re-evaluating the binding rules at the time the form is (re)shown - which
does not make sense to me.
 
T

Terry

Hi Again,
Well I just tried to duplicate my problem on a much smaller scale and
could not. So it is obvious that I have something else going on here and I
don't want you to waste anymore of your time till I get this a little more
sorted out. The complexity that I am dealing with is that I am sharing
bindingsources between forms which may be where the problem lies. I will get
back to you when I get clearer on the issue.
Thanks again,
 
L

Linda Liu[MSFT]

Hi Terry,

Thank you for your reply!

I look forward to your further information on this issue.

If you could reproduce the problem in a simple project, please send it to
my email box. Remove 'Online' from my displayed email address to get my
actual email address.

Happy New Year!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
T

Terry

For anyone who might be having a similar problem - this is a bug. It turns
out that whenever you show/re-show a form who's Mdi-parent property has been
set, the binding context is re-set, and any control currently not visible
(even though the visibility property is bound) has it's IsBinding property
set to False and never properly binds again in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top