Control focus styling - wpf

in above image you would notice that, doted rectangle indicating ComboBox is focused
But the problem is it exceeding the text area of ComboBox... how do I align it with text area WPF Style?
Thanks

Without seeing your ControlTemplate it's difficult to give the best way to change it.
One slightly hackish way to do it is set Focusable on the ComboBox to False and then set Focusable on the TextBlock (or Label) to True. This should make it so the TextBlock gets focus whenever the ComboBox should.
My best guess though is that you have some weird margins going on, the real way to fix it would be to straighten those out.

Related

How to get an existing property from style

I'm developing a WPF project where I need to validate textboxes on code-behind and then change the border color of those textboxes to some unknown color defined by the user configuration; the problem is that to overwrite the MouseOver effect I would need to set the value from XAML directly via ControlTemplate or Style.
Is there a way to get the current value assigned to the TextBox from XAML? Maybe binding it to itself?
I will appreciate any help you can give.
When validating a TextBox, or any control for that matter, it's common to use an adorner to display the validation error (in your case, setting the border color). You can have a look at an example here.
Using this method, you don't actually change the TextBox's border, but create a new visual layer on top of the TextBox that draws the new border around it. This is pretty much the way validations should be done in WPF, and it also solves your problem of having to deal with changing the TextBox's border value back and forth.

Can we overlay a WPF element by another?

I've this situation:
A label placed in Footer Cell of a RadGridView doesn't have sufficient width available in its container for displaying its full text.
Is it possible by any ways to have the label cross its container boundaries and show full text?
Thanks!
The space given to any element depends on the parent control or Panel that contains it, as well as its Width, Height, Horizontal and VerticalAlignment, and Margin. Normally you can manipulate some combination of these directly to change overlapping behavior but by using a DataGrid control you've given up a lot of that control since things like ColumnSpan are set up by the control internally. You could try setting negative Margin values and changing the Panel.ZIndex but I doubt those will help.
The best solution I can recommend without more detail is to use TextWrapping or TextTrimming to avoid ugly clipping, maybe in combination with a ToolTip showing the full text.
You can overlay any WPF element by another anytime. Only place where it fails is the WebBrowser control .The WPF WebBrowser has not been improved a single bit from WinForms WebBrowser. It is still the same simple activex control. However, you can bypass even that with a tooltip control.
I believe you can either set ClipToBounds=False to allow it to expand outside its area, or set TextWrapping=Wrap to allow the text to wrap.
EDIT: Forgot ClipToBounds is only honored in the Canvas control, so wrap your label in a Canvas and set ClipToBounds=False and it should work.

WPF User Control as item template

Hi
I am trying to render buttons as the item template of a list, to be displayed horizontally. The problem is that they don't 'butt up' to each other. They leave a small gap betwen each one. I have tried allsorts of things to cure it, but have'nt succeeded.
Any ideas?
Try using the WPF tool Snoop to work out where the margin is coming from, and then fix it.
(Negative margins = code smell, in general, IMO.)
Try a negative margin, setting cliptobounds to false, maybe that can help
It's most likely either a Border, Margin, or Padding on your item container (i.e. ListBoxItem if you're using ListBox) which can be corrected with the ItemContainerStyle or your Button's Border is using BorderThickness=1, BorderBrush=Transparent or null.
Use Snoop as Dan suggested to find out.

Focus on a Border in a Canvas

I have a Canvas and in it a Border. Now I want to give focus to this Border.
Can somebody please tell me how do do this?
First, make sure you have Border.Focusable = True. After that, just call Border.Focus() and you should be good to go.
I haven't tried it for Borders, but with a WPF ContentControl, I think I had to set IsTabStop and IsEnabled to true to get it to be able to accept focus.

On a WPF ComboBox, is it possible to set a different Foreground color for the textbox and the popup?

Basically my problem stems from a desire to have the textbox portion be white, and the drop down to be black. When I set the text to white, the drop down appears as I want it, but the text in the textbox itself is hardly readable. Setting the Foreground to black makes the drop down unreadable.
Is there a good way to handle this? I am still learning WPF.
Edit the ControlTemplate, You will see a TextBlock and another PopUp which again has a set of controls. Have a different ForeGround/Background for this TextBox,
Your best bet is to edit a copy of the template of the ComboBox and set the two of them independently.

Resources