|
Forget about LOB applications. Imagine there is a (zoomable, scrollable, pannable, rotatable) drawing area.
Now when the user click somewhere multiple things could happen (like, say, drawing a bezier curve), one of them is adding some text centered around said point. Which start by typing said text centered at point inline, ie. wysiwig editing. With the box around the text, previewing textblock handles, for later manipulation, such as rotation or translation (as in displacement)
modified 15-Dec-21 6:35am.
|
|
|
|
|
I just thought of a use case - when you're doing an app like Photoshop, that allows you to specify text objects. However, even those objects only grow to the extent needed, and properly process return/linefeed, and don't show scroll bars at all.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Yeah, well, mmm.. isn't what I just said?
Anyway, this is exactly what I am doing!
And, in other news, I got the text editor just appearing on my map, finally!
|
|
|
|
|
Actually.. you gave me another idea!
I am just going to prevent (or try to) any text longer than arbitrary length, say 256 characters. That might prevent some grief...
Oh.. look at that, TextBox.MaxLength !
|
|
|
|
|
Where can I find an up-to-date library or set of wpf converters?
I have also found that System.Windows.Controls contains 3 convertors. The closest I can find to a set.
I did a query wpf converters github - Google Search[^]
It found several candidates but they are quite dated.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
In over 10 years, I have yet the use a "converter"; unless it was my own code in a setter / getter. Your question make it sound like a necessity.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It is a feature of binding. I know some people have never used binding. I use it but would not recommend it for the faint of heart. When you have a good set of converters, binding is much more useful. Still very difficult to debug.
Do you know about Behaviors? Another obscure and little used feature.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
When I first learned PL/I, I made it my mission to use every possible language feature and function; whether it needed it or not.
My apps "bind" and they animate all the time; all without "convertors" and "behaviors". I just work closer to the metal.
I would suggest looking at the Community Toolkits for WPF / UWP though.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If you want to be close to the metal then you would do everything in assembly.
When the IBM PC first came out there was quite a discussion about the pros and cons of using assembly. Out of this the one thing I remember was the story about the cowboy that liked to chew on metal nails. Do you remember it?
Someone asked a cowboy why he like to chew on nails. He answered, when I look in a mirror and see all my broken and cracked teeth, I look tough. When it pokes me and cuts me in the mouth, the pain makes me feel tough. When there is blood running down the corner of my mouth others will know I am tough.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
Converters and behaviors are another layer of indirection; they don't make life easier.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I sometimes think binding is a new form of spaghetti code. Converters are kind of like the meatballs. All covered in sauce, a kind of slippery connection. Binding and converters are a great idea but are almost rendered useless by the lack of debugging tools.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
|
A different kind of converter. This is about the old Converter dialog box. Not the binding converters.
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
So I must reveal my ignorance ... I never learned about "binding converters".
How does a "binding converter" work? What does it do? How do you use it?
|
|
|
|
|
This is a very glossy overview
I assume you know what binding is since you are watching this forum on WPF. Let’s say you want to bind a bool to visibility. Bool has only 2 states, true and false. Visibility has 3 states, Visible, Hidden, and Collapsed. (Ignoring null). A binding converter will convert bool to visibility.
As stated, before binding and converters are not for the faint of heart. This link will get you started, barely.
Value conversion with IValueConverter - The complete WPF tutorial[^]
So many years of programming I have forgotten more languages than I know.
|
|
|
|
|
OK, I have used and written that kind of converters. I just didn't trigger on the name "binding converter". I though it was some way of converting the binding as such, not the value type!
|
|
|
|
|
michaelbarb wrote: they are quite dated
Really? The first result[^] was updated two years ago. WPF hasn't changed that much since 2006.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I've always written my own converters. I have about a dozen or so. I have a bool-to-visibility converter that can be configured (in XAML) to set the visibility to any of the three possible values according to the bool value (just as an for instance).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
What do you want to convert?
I rarely have to convert (some yet unidentified) BCL class to other BCL class. Usually I need to convert a business class (i.e. local to your code) to perhaps a BCL class (such as color, image source, etc).. You need to write your own converter there (come on, it's only 2 methods to implement, or just 1 in case of one way binding).
Also, if you make some view model, view model can directly expose a property of the right type and have value conversion happening in the property setter.
|
|
|
|
|
I recently did an app and the company library had a set of about 30 converters in it. Mostly common things. I found myself using binding and converters much more than I ever had in the past. Simply because I did not have write the converters. They are not hard to write, it is just I am lazy. It got me wondering if out there somewhere there is a better worked out converter library????
So many years of programming I have forgotten more languages than I know.
modified 14-Dec-21 10:33am.
|
|
|
|
|
forget it... converter are the simplest thing to write. if you feel the need to download premade one, you need more practice writing ones!
also, most of them, apart perhaps from the classical boolean to visibility, null to boolean, and null to visibility and color to brushes and pens, are specific to your application
|
|
|
|
|
I have two ListBoxes on the screen, and this is my requirement:- Upon loading the window, the first listbox (ListBox1) should be populated with items (which is happening correctly), but I also want the first item to be selected. This is to happen via MVVM, and not through codebehind. And upon selecting in the first listbox (ListBox1), the second listbox (ListBox2) should be populated (which is happening correctly), and its first item (of ListBox2) is to be selected.
How is this listbox selection to be achieved via MVVM?
modified 21-Nov-21 0:50am.
|
|
|
|
|
Your listbox1 needs to handle the SelectionChanged event, which when executed, populates the collection for listbox2. Since listbox2 is bound to the appropriate collection, it will automatically update itself.
You didn't say whether or not you wanted to retain the selected item from listbox1 in the viewmodel.
I'm assuming that your bound collections for both list boxes are ObservableCollection s...
To automatically select the first item in listbox1, simply set the SelectedIndex property to 0.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Ahh ... but you didn't say "where" to set index to 0. He wants "no code behind". I guess you can set it in XAML, but isn't it "0" anyway? (Actually, I thinks it's -1 when newly loaded. Shrug)
Just taking digs at "no code behind" MVVM; not your answer.
It's "plumbing". To say you can't put it in a loaded event (as "code") is OCD, IMO.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
"No code behind" is a pointless endeavour, and a highly artificial requirement. It also means that he app is virtually impossible (or at least a pain in the ass) to debug. I make it a practice to put as much as possible in the code behind for this very reason. Sure, control interaction can be put into the XAML many times, but I pretty much use code-behind for everything.
In the real world, you do what works, and use the simplest means possible. Doing the work is no time to exercise classroom theory or hypotheticals. Experienced programmers (like us) are cognizant of these facts and are much more efficient coders as a result.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|