Hi All,
I have a custom UserControl that is used as the list item in a listbox
in my main WPF window.
Is it possible to have key bindings that apply to every instance of
the user control? For example, I have a keybinding Alt+R for a button
in the UserControl. However when there are multiple instances of the
UserControl in the listbox in my main WPF window, pressing Alt+R just
shifts the keyboard focus to the button in the first user control.
Pressing Alt+R subsequently just makes the focus cycle through the
same button in other user controls.
Thanks,
Sundar 6 5363
I tried the suggestion in "http://neilmosafi.blog spot.com/2007/04/
default-buttons-in-wpf-and-multiple.html". But still the same
behavior :(
On Thu, 14 Aug 2008 08:39:14 -0700, sundarvenkata
<su***********@ gmail.comwrote:
Hi All,
I have a custom UserControl that is used as the list item in a listbox
in my main WPF window.
Is it possible to have key bindings that apply to every instance of
the user control?
Key input is necessarily focus-based.
But, you could add a method in your UserControl sub-class that the parent
window can call. Then, in the parent window filter the keyboard input so
that it sees key input before its children do, and have the parent window
call the UserControl's method on each child control when the appropriate
key is pressed.
I don't know the exact override you'd use for a WPF window to do this, but
in the Forms Control class, a parent Form instance could override the
ProcessKeyPrevi ew() method to be given the chance to see key input before
child controls handle it. Maybe there's something similar in the WPF
classes.
Pete
I see your point. But doing so defeats the reusability of the
UserControl. Every time I use this control in some other form, I need
to ensure that the parent control calls the appropriate methods in the
child control to handle keyboard events. Is it possible to scope the
key handling such that it is handled only by the user control and not
passed up the control hierarchy?
On Thu, 14 Aug 2008 09:12:27 -0700, sundarvenkata
<su***********@ gmail.comwrote:
I see your point. But doing so defeats the reusability of the
UserControl. Every time I use this control in some other form, I need
to ensure that the parent control calls the appropriate methods in the
child control to handle keyboard events. Is it possible to scope the
key handling such that it is handled only by the user control and not
passed up the control hierarchy?
Maybe I misunderstood your question. If you only want the UserControl to
handle the keyboard input, then what do you mean by "to have key bindings
that apply to every instance of the user control"? The way I read that,
you want a single key input to cause something to happen in every instance
of the UserControl that you've made.
Are you saying that's not actually what you want? If so, could you
elaborate on what's wrong with the default "cycle through the buttons"
behavior?
If I didn't misunderstand, then I think you could implement this in the
UserControl only, but I would say that would be a bad design. In
particular, of course any given UserControl receiving key input could
inspect all of the children of its parent to see if there are other
UserControl instances that it can forward the key input to. But then what
happens when someone wants to use more than one of those UserControl
instances in a situation when they _don't_ want that behavior?
Putting the logic in the parent seems to me to be a simpler, more
adaptable, more sensible design.
Pete
I get your point. I had some weird idea that I can encapsulate a
keyboard response behavior of the UserControl in the definition of the
UserControl itself. But since keyboard inputs are usually handled at
the form level, I think I should go with your suggestion.
On Aug 14, 8:35*pm, sundarvenkata <sundarvenk...@ gmail.comwrote:
I get your point. I had some weird idea that I can encapsulate a
keyboard response behavior of the UserControl in the definition of the
UserControl itself. But since keyboard inputs are usually handled at
the form level, I think I should go with your suggestion.
If you really want to do that, you can - you can track changes to your
Parent property (it's a dependency property), and when it changes,
follow the parent chain all the way to the topmost element, and
subscribe to its KeyDown event (and unsubscribe from event of your
previous parent, if any).
But I would second the notion that it is not, in general, a good idea
to do that sort of thing. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: roberto3214 |
last post by:
Hi Guys,
How are you? I have recently begun some testing on IIS 6.0 in regards
to an asp.net application. After lots of testing I decided to create a
simple 1k page size webpage to find out whats the max rps I can
achieve. So I installed Microsoft Application Stress Tool (WAS) and
started testing. I setup basic 2 tests page does no processing
whatsoever:
TEST 1
|
by: Kallis |
last post by:
Hello,
I have the following situation when trying to localize my software:
I have BIG solution with about 80 projects. In one of the projects I
have a number of dialogs (the dialog project :-) ). I have decided
that I do not want to use the "form"-mechanism (using the property
"localized=true") for localization since the strings I show are not
that "constant" during the life time of the dialog. Thus, I have to
put the resources in...
|
by: Guadala Harry |
last post by:
Is there any way for one Session to remove and update objects in another
Session? I seriously doubt it, but thought I'd ask. Here's why: I have some
data that is unique per user (or per session - similar to "welcome back,
Jim" after Jim logs in) and consumed across multiple pages. This "per user"
data lives in a database, so toward improving runtime performance I want to
cache data supporting this and similar per user features. Because the...
|
by: needin4mation |
last post by:
Hi, I have to decide between a per device and a per license issue. We
have several web services that have functions that use things like
LOGON_USER. If I have a per device license, does that mean things like
LOGON_USER go away? Or that I cannot use Windows Integrated
Authentication for UNC file server stuff, web pages, etc.? Thank you.
|
by: Randy Yates |
last post by:
I'm a complete newbie to postgres so please look the
other way if these questions are really stupid.
Is it legitimate to have one database per data file? For
organizational and backup purposes, I'd like to keep the
database files for each of several projects separate.
This means, e.g., that postmaster must have multiple
instances going simultaneously?
I'm thinking the answer is NO because, for one, the TCPIP
| |
by: bruno at modulix |
last post by:
Hi
I'm currently playing with some (possibly weird...) code, and I'd have a
use for per-instance descriptors, ie (dummy code):
class DummyDescriptor(object):
def __get__(self, obj, objtype=None):
if obj is None:
return self
return getattr(obj, 'bar', 'no bar')
|
by: Matias Jansson |
last post by:
I come from a background of Java and C# where it is common practise to have
one class per file in the file/project structure. As I have understood it,
it is more common practice to have many classes in a Python module/file.
What is the motivation behind it, would it be a bad idea to have a guideline
in your project that promotes a one class per file structure (assuming most
of the programmers a background similar to mine)?
|
by: Joseph Geretz |
last post by:
I need to calculate miles per degree longitude, which obviously depends on
latitude since lines of longitude converge at the poles. Via Google, I've
come up with the following calculation:
private const double MilesPerDegLat = 69.04;
private const double EarthRadiusMiles = 3963.1676;
private static double PiDiv180 = Math.PI / 180;
double MilesPerDegLon = MilesPerDegLat * Math.Cos(Latitude * PiDiv180)
|
by: bakxchaixDD |
last post by:
I DON'T GET THIS
project:
Many treadmills output the speed in miles per hour. However, most runners think of their pace in minutes and seconds per mile. Write a program that inputs a decimal value for miles per hour and converts the value to minutes and seconds per mile.
Sample input, output:
For input 5.5 mph, the output should be 10 minutes and 55 seconds per mile.
For input 4 mph, the output should be 15 minutes and 0 seconds...
|
by: raveekumarg |
last post by:
hi
what is the difference between per seat , per server , per processor and i am new to sql 2000 , pl do explain the same.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |