How to set animation in silverlight listbox Item? - silverlight-4.0

I have one observable collection with user control. And I am bind it in listbox. I want to set animation on listbox item. Like when mouse over on user control that time start some storyboard and when mouse leave from listbox item that time set storyboard to stop.
How can i do this?
Any idea?

You could start by defining your mouse over and mouse leave storyboards on your user control and passing your storyboards to your usercontrol view model in the manner described here:
how to call an animation in mainpage.xaml from login.xaml in silverlight 4
You could then assign mouse over and mouse leave events to your user control. Inside the events you'd cast the sender's DataContext to the type of your user control view model and then call the appropriate storyboard Begin method off of that view model instance.

Related

Objective-C does not execute change method for a NSPopUpButton

I have a view with a popup menu. In the view controller I implemented a method for reading which tag/item is selected by the user.
- (IBAction)popUpChanged:(id)sender
{
self.item = [sender selectedTag];
}
If I choose a menu entry/item the method popUpChanged is executed.
In another class I have a button. By clicking this button the popup menu of the view controller should be set to the item no. 1. Therefore the button-action executes the following line.
[_viewController.popUp selectItemWithTag: 1];
After executing the selectItemWithTag:1 the popup menu is set to the item 1, like expected. The state/item of the popup menu is change, but the button click does not result in the execution of the method popUpChanged?
Can somebody please explain it to me why the method popUpChanged is not executed?
-popUpChanged: is what you set as the action method for the pop-up menu. Programmatically changing the pop-up menu is not an "action" on that pop-up menu. The action is only triggered for user interactions with the pop-up menu.
It is a fairly general pattern within Cocoa that programmatic operations on controls don't go through the same pathways as user manipulations of those controls. For example, a control can be disabled so the user can't change it, but you can still change it programmatically. Or a window's delegate can prevent closing the window in its -windowShouldClose:, but programmatically closing the window with -close is not subject to that (although -performClose: is).
In any case, given that you're programmatically changing the selected item in the pop-up menu, you can programmatically invoke the action method or, more usually, do the same operation as the action method would (e.g. [_viewController.popUp selectItemWithTag: 1]; _viewController.item = 1;).
Or, even better, bind the pop-up button's selectedTag binding to the view controller's item property and a) eliminate the action method, and b) replace your programmatic manipulation of the pop-up with programmatic setting of the view controller's item property.

UserControl that will notify viewmodel if user clicks anywhere outside of of it or it becomes no longer visible

I have an element that is connected to a viewmodel that uses MediaCapture to record audio. If the user is recording audio(presses the record button), and then navigates away from it (clicks somewhere else in the UI, switches windows etc...), I would like to stop the recording in my viewmodel.
I would like to be able to bind a dependency property on an element that will notify my viewmodel if the user clicks anywhere outside of the element or it becomes no longer visible to the user).
Is there and event inside a custom usercontrol that I can connect to a DP that will report what I'm looking for?
Specifically for page changes you can override the OnNavigatedFrom method of the page get the view model via
var viewModel = LayoutRoot.DataContext as MyViewModelType;
And then invoke your stop record method on viewModel ciewModel.StopRecording ()
For tapping other control or the recording control being moved off screen due to scrolling ..
I would implement and event aggregator which was known by pages and ui elements so any event they respond to (tap /scroll) that you wish to use as a trigger for making the recording stop would publish a "StopRecordingEvent" that your view model could subscribe and listen to the event aggregator for.
http://developingzack.blogspot.com/2012/09/what-why-and-how-event-aggregator.html?m=1

NSColorWell not sending action on click?

Inside my .xib, I've placed an NSColorWell inside an NSView, and connected an IBAction in the controller to the NSColorWell's Sent Actions (via File's Owner). I figured I would respond to a click in my controller and send activate to bring up the NSColorPanel.
But unlike other my controls, I'm not getting the IBAction called. Clicking invokes a drag action on the color. I noticed this control doesn't derive from NSActionCell (like all my other controls). What's the proper control that is supposed to be used to both display a color and invoke the NSColorWell when clicked?
(note: this is Xcode/IB 3.2.x)
You listed both osx and ios in the tags, but I'm guessing this is an OS X problem.
There is a "Bordered" checkbox in IB's Attributes Inspector for NSColorWell. This toggles between a button-style color well, which is what you're asking for, and a color well which you can only drag a color swatch from. Make sure that's checked and you'll get the action like you're expecting.

Get the representedObject values of NSCollectionViewItem NSButton click

I have read some questions and I find some very confusing and I don't really know if they answer my question.
I have an NSCollectionView implemented and connected to a Core Data context, everything shows correctly.
Now what I have is buttons in the view prototype, and when I click this buttons I need to get the value of the representedObject of that cloned view.
I have read and read and some parts are confusing to me, so I'm looking for a simple explanation.
Thank you for your time.
An action method takes one argument:
- (IBAction) collectionViewButtonClicked:(id)sender {
}
That sender is the control or other UI element (e.g., menu item) that sent the message.
With that argument, when your action method gets called, you know which button was clicked.
A button is a kind of control, and every control is backed by at least one cell. Cells have represented objects, too.
So, first, set the represented object of your button's cell to the collection view item that owns the button. (You can do this in the nib editor.) Then, in your action method, get the button's cell, then the cell's represented object (which is the item), then the item's represented object.
If the representedObject outlet doesn't show up in the nib editor, you probably have the button selected, not its cell. I recommend opening the nib editor's outline view using the button in the lower-left and then never, ever closing it.

Enable text box when checkbox is ON using objective c

How do I enable a text box when I check the checkbox through bindings in Cocoa?
Bind the checkbox's value and the text field's enabled to the same property of the same object—usually either your File's Owner (typically a window controller, view controller, or document) or some kind of object controller (such as an array controller).
First you connect your text box to an IBOutlet.
And instead of using binding, you can set your button to fire an action method when it is touched (this is called an IBAction and there's a bit more detail in this related question)
When the state of the button (or in your case, checkbox) changes, the IBAction method gets called and based on the state of the checkbox, you can enable or disable your textbox via the outlet you connected.