Suppose I have an element (in my case, a StackPanel) that contains several UI elements (in my case, lots of textboxes contained in various Grids contained in etc.etc. contained in the StackPanel).
I want to know whether any one of those textboxes has focus. (I want to bind this property to a View-Model property.) Is there a property for this? If not, what is the simplest way to bind to this kind of information, without having to first extract all the textboxes? (They’re generated by templates.)
You could use IsKeyboardFocusWithin. What kind of binding are you wanting to do to it? If it's something simple like you're wanting to change the background of the stackpanel if a textbox within has focus, you should be able to use this as a style trigger.
Related
i used PropertyGrid control to display properties on gridview.
i have taken an reference of this link http://www.c-sharpcorner.com/article/using-property-grid-in-c-sharp/
which is showing like this
But i need checkbox just before the property name shown in red mark on check/uncheck for any property i need to build expression.
I recommend reading this: How do I change boolean properties with one click in PropertyGrid.
It extends the PropertyGrid control and defines its checkbox controls using UITypeEditor.
As Reza mentioned, your choice of control does not appear optimal. You should probably create a form with TextBox, CheckBox, ComboBox etc. Or make use of DataGridView if your display is catering for multiple records at same time.
If you most definitely want to customize PropertyGrid, here is my another answer which might help you start with.
Linked answer:
You can make use of TrackBar. Note that PropertyGrid by default does
not allow you to add controls like these to it. So, you will need to
do some work here. You will need to create a class that inherits from
System.Drawing.Design.UITypeEditor. Next you will have to set the
editor attribute for the property that has to display track bar as
control. Note that unless you do custom paint, it will be shown as
modal dialog or as dropdown editor.
In my WPF application, my Viewmodel has a boolean property IsOwnerOf and a string property Title. If IsOwner==false, I want a TextBlock displaying the Title (because if you're not the owner, you should not be able to edit it) and if IsOwner==true, I want a TextBox displaying Title - obviously at the same place in the view.
Also I don't want to do it codebehind since I follow the MVVM pattern. Thought about Style.Triggers, but with them I can only influence attributes of an element, not the element type itself, or can I?
EDIT:
Practically the answers below regarding triggering Visibility or IsReadOnly work, but I still would like to see a conceptually better answer! What if I replace the TextBox resp. TextBlock by elements that don't have these convenient properties? There must be a better way than creating both and hiding one of them, that just doesn't sound right...
The easiest option is to always drop a TextBox and bind it's IsEnabled or IsReadOnly property to the IsOwner flag.
You can also use a DataTemplateSelector to achieve this.
You can use triggers to change the Visibility of your TextBlock and TextBox using a BooleanToVisibilityConverter
I want to add a tool tip for items in a Property Grid. When the user hovers over a property I want the tooltip to display a hint about the usage of that property. The hint string should be different for each different value of the property — for example if one property is a list of strings each string would have a different hint.
Is this possible?
The PropertyGrid is not very flexible and doesn't expose any of the individual controls on it. You can access the control (textbox or dropdown) that you're looking to show the tooltip on via reflection but that is far from trivial, especially since all the control classes are unique and internal to the property grid.
Using the Description attribute is by far the best value. If your list of strings for that property aren't obvious enough to portray their meaning without providing a tooltip, perhaps you should revisit the string text you are showing for each item in the list.
Basically, I have a control that I want to extend from the Selector Class. I know that Selector allows for multiple child items to be selected, but I don't want that. I only want a single child to be selected at a time.
Is there a setting that I'm not seeing in the Selector class that distinguishes between single/multi selections allowed, or is that something that is controlled by the class that I write that extends the Selector class?
Have you tried the MultiSelector? It has a CanSelectMultipleItems property that might help.
Selector doesn't have support for multiple selections. ListBox, and therefore ListView, do support multiple selections.
In any event, you are responsible for the actual selection of items. Selector just exposes the properties and events that deal with selection.
hey,
Does anybody knows a way to set a hidden value to a ListBox Item.
As an alternative i can use another listbox simultaneously.
Thanks.
You are probably looking for the Tag property. It holds an object type, which means you can save a reference to anything in there.
Although before setting on using the tag property, take a look at ItemsSource. Basically you can tie a collection of things to be the provider for your listbox, it's usually a superior alternative to dealing with Listbox items individually.