I am trying to format a property grid, working few years on wpf has rusted my winforms knowledge.
I want to make property name text bold in some cases, I want to use a bool return value from a method, and decide if property name is to be displayed as bold.
Any ideas on how to achieve this, what property what event!?
Back in the day...
Really, this is going way back. I don't remember that there was a way to control the property name appearance directly. You could make sure your property descriptors had categories and those categories would be bold.
Also (and I don't think this is still true in "later" versions of Windows), you could return true from your property descriptor's ShouldSerializeValue method...and it would cause the PropertyGrid to display the property value in bold.
Also seems like you could identify one of your properties as the object's default property (in the object's type descriptor). Seems like there were differing behaviors depending on the version of Windows...after XP, I think this would float the property to the top...but maybe XP and before it would make the property name bold...but I could be misremembering. I've slept more than once since then.
With the property grid, I seem to remember running into the argument that doing any more formatting might interfere with all the complex layout the grid was already doing on the object's behalf. Back then, I was using the property grid to format hierarchical objects...and I remember being impressed with it's capabilities despite it's relative lack of formatting control.
Of course, after spending time in WPF, you can't help but feel like you can affect anything and everything, yes?
Related
Our application has many TextBoxes that we disable at appropriate times. (We set the IsEnabled property to false). Our customer now wants the content of the TextBoxes to be non-changeable, but able to be copied. We can do this by setting IsReadOnly to true and IsEnabled to true.
I don't really want to go to every place in the application where text boxes change state and twiddle with those settings. How can I localize changes, such that I don't need to make a large number of edits? Basically, I want to do something that would be almost equivalent of redefining the set part of IsEnabled, when the value to be set is false. (BTW, our customer would also like us to do some other related changes, such as setting the background color of the text box to a non-default color when "disabling" the text box.)
One way to do this would be to create a subclass of TextBox that allowed you to make these type of changes. However that requires that you change your application to replace all occurrences of <TextBox ... with your control:
<myControl:MyTextBox....
which doesn't really solve your problem of not wanting to change all the code.
However, it would enable you to do the other changes you mention - changing the background colour, etc. a bit easier (though that can be also achieved by overriding the default style in XAML).
I dont really understand your question but I think it would be easiest to create a Background Worker that checks with if ( MyTextBox.Enabled == false ) if the textbox is enabled/disabled.
This is probably very simple to do, but I'm having a brain fart (being sleep deprived will do that to you).
I've got a WPF User Control and I want to expose a property (as read only) of one of its child controls to the outside world so I can bind to it.
Whats the best way?
I think I should expand on this, as it may be more fiddly than I gave an impression of. I've got a grid with a column in it of width "*". When its contents have been loaded I want to be able to get the ActualWidth of the column and pass that out of the usercontrol as a read only property (so I can bind another control to the same value and have it match the size).
I'm not sure how to set up a dependency property to do this properly.
Is it possible to bind a property name. I seem to come up with run time errors when I try.
For instance:
<button Name="{Binding UniqueID}" Click="ButtonHandler">
This being in a header for a collection in a grid-view...
You can't bind Name, sorry. It's used for too many things internally and stuff would surely go crazy if you could. The docs are a bit vague, but do say this: (emphasis mine)
You cannot use the string value of Name as a
direct source value for a data binding source. If you have to display
the same string value as Name in UI with binding, you should replicate
the same value to the Tag property, which can be used as a property
binding source. Also don't use Name as a binding target.
(MSDN: FrameworkElement.Name)
However, if you want to attach random extra data to UI controls, I would recommend using attached properties instead. That way they're specifically associated with what you're doing and will be appropriately typed, unlike Tag.
(MSDN: Custom Attached Properties)
Well, I've read the documentation over and over and cannot find a way to make it work. The documentation doesn't say you cannot do it, but it doesn't say you can do it either.
However, I found two workarounds. Instead of binding the name, if you aren't using Tag or DataContect, you can find to those and in the handler extract them by casting as a string.
It's not elegant, but, it does seem to work as expected.
This is a getting started question about how to create a reusable wpf slideshow control:
that displays a sequence of any visualizable elements e.g. a series of Image controls or a series of UserControls (should I target ContentControl, or is there a broader type that encompasses more visualizables/controls?)
the control should be able to accept an IList of some kind, which would be the elements/slides to present
the control should expose an Interval property that determines the duration of each slide, but i dont even know the basics of how to get started with that in terms of offering that property to be configured in xaml?
and what should the container be, if any, for the individual slides/controls that are passed in?
To start with, you should probably create a UserControl which contains an Image control, and perhaps Next/Previous Buttons, and anything else you may need. These would all be laid out as normal using a variety of panels, you could probably style most of it with just a Grid.
After that, your UserControl will implement the ImageSource (your IList, or IEnumerable of images), and your interval as dependency properties. These are then settable in XAML.
You would then write the logic which loads the next image and sets it as the Image's Source property, this could happen in the change event for the ImageSource property. You can then get as advanced as you wish with Image preloading/caching etc.
I've just delved into WPF myself for a "Slideshow" like project where I'm showing customer order numbers on screen for a period of time before showing the next, and using Effect/Transitions/Storyboards to move to the next frame. I found a good article on CodeProject
I used a Grid with 2 rows:
Contains my "Changing area".
Contains static information (logo, controls etc).
Rememeber to set "cliptobounds = true" on your changing area if you use any sort of transforms on it. (I know you said you aren't using transitions initially, but once people see it, they'll be asking).
Dependency properties are also easily built in C# if you just type propdp and hit tab.
In WinForm, I have a combobox with DropDownStyle set to DropDownList (so can't enter a Text). In the properties window, there is the Items property which is a string collection. I enter all my values.
But now, I would like to set one of these value by default (instead to have the empty entry at run-time). I know how to do this via coding, but I am pretty sure (damn memory) that it was possible to set one of the value in the string collection as default by adding a special symbole in front of the line.
Anybody know that symbole? Or my memory is playing me trick and it is not possible to do it via the designer?
Doesn't look like it can be done when using a DropDownList. From here it is suggested that you can set the text property to the default value you want, but this will only works in a DropDown rather than DropDownList style.
I'm sorry but that is not possible within the Designer only, since the Text property is used for this feature and that property is ignored/cleared when the using a DropDownList.
If you don't mind having your data values outside of the Designer, you could probably use DataBinding to accomplish this since the DisplayMember and ValueMember properties of ComboBox can be used in the Designer and would set the display value. I don't normally use DataBinding so unfortunately I cannot provide code examples - perhaps another user can chime in?