In my WP7 application, I have a ListBox populated with buttons. I have a 'Pressed' visual state configured, and it works great. However, I would like to disable that 'Pressed' visual state (temporarily set it to do nothing) while the ListBox is scrolling.
I've created an event handler for detecting when the ListBox is scrolling (using Peter Torr's blog entry here. Using that event handler, how can I alter/disable that 'Pressed' visual state, and also return it to its originally (through XAML) defined state? The ListBox 'Generated Items' template is the button control, which itself is templated to use my custom 'Pressed' state animation.
Thanks!
This is not execly what are you looking for, but you can try setting
myButton.IsEnabled = false;
I assume your goal is to prevent user from clicking a button while scrolling.
Related
I have a search screen in my WPF application. The screen is implemented as a UserControl in a TabItem of a TabControl. When the user switches to the Search tab, I want the focus to go into one particular field.
So I added a Loaded event handler to the UserControl tag in the Xaml and I called the Focus method of the control I want to have the initial focus in the Loaded event handler. This worked great until I upgraded the Telerik control library I'm using today. Now, when I switch to the Search tab, the focus is NOT in the field I want to have it, but I can't tell what control does have the focus.
The field I want to have focus already has GotFocus & LostFocus event handlers for other reasons. I remembered that in Win Forms, the LostFocus event handler arguments tell you which control is going to get the focus. So I put a breakpoint in my LostFocus handler & discovered that the arguments to the LostFocus event handler in WPF don't include that information.
How can I figure out where the focus is going without putting GotFocus handlers on every control in my UserControl?
Tony
You can try putting your breakpoint on the LostKeyboardFocus Attached Event instead of the LostFocus Event. It uses the KeyboardFocusChangedEventArgs Class which does have properties that show which element had focus and where the focus is going.
private void textBox1_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
textBox1.Text = ((FrameworkElement)e.NewFocus).Name ;
}
Try to press Tab Key and see if it helps you find the control in focus.
You can also use Snoop as suggested in this Q/A: Any tips on debugging focus issues in WPF?
For starters, Snoop shows the current focused element and the current
FocusScope in the status bar.
You can get it to show you all the GotFocus and LostFocus events:
1. Run your app.
2. Run Snoop.
3. Choose your app in the dropdown.
4. Click the binoculars ("Snoop") button.
5. On the right pane, click the Events tab.
6. Click to bring down the dropdown.
7. Scroll down to the Keyboard section and check GotKeyboardFocus, LostKeyboardFocus, and optionally the PreviewXXX events.
8. Now do what you need to do to manipulate focus and watch the Snoop window.
Similarly you can track the FocusManager events the same way.
The ASP.NET GridView (and other controls) has the very handy DataBound event, which fires after the GridView finishes databinding. Is there an equivalent event for the Silverlight ListBox (WP7.1)?
My ListBox changes constantly based on user input and I would like to scroll the listbox to a certain item.
As far as I know there is no such event.
But you could use a more generic change listener like ItemsChanged:
listBox1.ItemContainerGenerator.ItemsChanged += new ItemsChangedEventHandler(ItemContainerGenerator_ItemsChanged);
This will also react on normal list changes but you can easily filter these.
The ListBox has a SelectedItem property. Just set it to one of the items, or set the SelectedValue and that will automatically scroll it to make visible.
Here is the MSDN reference of that property: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditem.aspx
I was wondering if I can have a ComboxBox with a Treeview as the selector rather than a list?
I note that there is a ComboBox.ItemsPanelTemplate, but I don't know what I need to do to get this to work?
I could build a control 'from the ground-up' with a separate TextBox, Button and TreeView in a PopUp control, but wondered if there is an easier way.
Lee
Are you just wanting the combobox for presentation purposes regarding the treeview?
Why not use a treeview as is and just trigger the display via visibility or animation from a button or control of some sort?
I am working on similar theme as we speak. I am using the Expander control from the Silverlight Toolkit with a TreeView control inside it. When an item is selected in the TreeView, it sets the Header of the Expander and then collapses the Expander.
Initial tests indicate it's OK but as I say, just started with it myself. Will let you know if I hit any stumbling blocks.
My WPF application consists of a main window with a tab control which has a series of tab items, each hosting a user control.
I'd like one of the user controls to be able to trigger the application to change focus from the current tab to a different one.
Is there a way for the user control to trigger its tab control container to change to another tab item?
The WPF system provides the RoutedEvent. This special kind of event can be created to be catched by every element in the tree. With this way you can fire the event inside your user control, and catch it in the TabControl that will do everything you need. The tab control can catch the event cause of it lies in the element's tree of your window.
You can start from here:
http://msdn.microsoft.com/en-us/library/ms742806.aspx
You'll need a Bubble Event.
Hope this helps.
You can have a property that binds with SelectedItem property of TabControl.
I'm using a modified form of treeview, for the treeviewitem there is a template to show a textbox with a done button in a popup. I have used a static class to find if the mouseOver
(IInputElement currentPosition = Mouse.DirectlyOver;) event on any of the other treeview item to highlight them other than the one in Popup textbox. Items are added dynamically to this treeview. I'm using MVVM model here.
The problem is that when the first item is added and is in Popup textbox , the mouseover for the entire application is somehow turned off, which is not required. But on adding the second item and leaving it in the Popup textbox, the mouseover is switched on, i.e the treeviewitems get highlighted when mouseover occurs. this happens alternately....
What is capturing this mouseover event..??
try using snoop it can tell you what events are being raised, handled. and its a cool tool as well for the wpf man (or woman:)