I want to set up an event to run when the Visibility is changed on a WPF Canvas control.
canvas1.VisibleChanged += new EventHandler(canvas1_VisibleChanged);
I have tried the above but it doesn't work, anyone know how to do it ?
You're looking for the IsVisibleChanged event, which applies to ALL UIElements:
UIElement.IsVisibleChanged
More Information: IsVisible is a read-only Dependency Property. It is a calculated value, and the Visibility Dependency Property affects it. This is what you should use to detect if you're UIElement is visible or not.
Now, if you really really wanna just check for the Visibility DP changing for whatever reason there is a way to do so: http://agsmith.wordpress.com/2008/04/07/propertydescriptor-addvaluechanged-alternative/
Though, I'd still stick with just tracking the IsVisibleChanged.
The normal WPF Canvas object does not have a .VisibleChanged event, so you can't assign an event handler to it.
Related
I have a WPF window with about 30 controls on it (text and comboboxes). There is no binding, I just populate them from a dictionary in Loaded event. I need to be able to know if user has changed any of them. Is there a way to do it other than setting a flag in 30 "Changed" events?
I tried to research it and saw a lot of info on implementing IsDirty property but I am not sure if it is applicable to my simple unbound window.
You can use one changed event handler that is attached to all 30 events.
I have used a custom control in wpf from Source code for multiselect. that control is a multiselect combobox with checkbox. but selection changed event is not present in that.I am trying to create a selection changed event using DependencyProperty. I am new to WPF. I don't know how to use DependencyProperty for creating events. Can Anyone tell me how to create selection change event in that control.
Combobox image is here
You need to use a RoutedEvent.
Create a custom routed event
But better yet you can use an existing routed event from the selector class called SelectionChanged
Raising the selection changed event from your code: psedo code since i am not near vs.
SelectionChangedEventArgs args = new SelectionChangedEventArgs();
args.AddedItem.add(... how ever is checked ..);
args.RemovedItem.add(... how ever was unchecked ..);
this.RaiseEvent(args); // this your control.
I have a view model property that is set to runtime objects. I want to trigger an animation whenever this property changes, so I was planning to use DataTrigger. However, DataTrigger obviously has the requirement for a Value property--one that I don't know at design-time.
Is there a built in way to trigger an animation whenever a value changes, regardless of what it changes into?
I saw this question but I was wondering if there was anyway to do it purely in XAML. Otherwise I figure I could probably fire an event from my View Model whenever the property changes and listen to that.
One method would be to create a User Control with a dependency property and then bind both of your other properties to that i.e. one at compile time and the other at runtime. Alternatively you could use an Attached Behaviour to do the same thing.
Can add a boolean property and trigger the animation based on the bool property. Whenever the original property changes, set and reset the boolean property so that it triggers the animation and also goes back to default value for next notification.
I am creating some Animations to animate the change between values in a Textblock.
From what I've seen, I can use a DataTrigger to trigger then animation when the Textblock's value == something, but is there a way to use the same mechanism to trigger when its changed? (That is, I don't care what the new value is just that its different)
I think this is supported in WPF using the EventTrigger with TargetUpdated but this doesn't seem to exist in Windows Phone.
I believe what you're looking for is the PropertyChangedTrigger
Hope this helps.
How to change the color of text, when a control is disabled.I want to set different color when control is disabled in c# winforms.
Edit: I had made the same mistake as Cody in the comments so corrected my answer.
It depends on which control it is.
For example, if it's a TextBox maybe you could make it ReadOnly instead of disabled. And for some other controls you might be able to do similar things to make them appear disabled without actually being disabled.
However, if you want to do it properly you need to make them Owner-draw or override the OnPaint event and draw the text yourself.
You can just do it manually -- when you disable the control, just change the text colour too?
If you have many controls, you can do this:
attach your form OnChildAdded event
in the event, use if ... is of type structure to determine control type
depending on the control type, register proper OnEnabledChange event
in the event, change text color appropriately
That way, you will have a piece of code that will work for all your forms and will gradually expand to use all the controls you need.
I'll provide some code if that's the way you want to go...