enforce WPF ContentControls to have maximum width - wpf

I have ContentControls like ComboBox and TextBox inside of a Grid or a StackPanel. I want them to have the maximum possible width. How do I achieve that? I've noticed that Button has maximum width any way when it is added to a StackPanel, but ComboBox and TextBox do not. I've tried setting ContentControls' Width="*", but that doesn't work.

Did you try HorizontalAlignment="Stretch"?

Related

WPF Textblock > Change Text when text is too wide

I have a textblock inside a fixed width grid. The textblock shows selected items from the viewmodel like Red, Blue, Gray.
When there are too many selected items to display I want to change the text to '10 Selected Items'. How can I determine if the textblock's current value is wider than the grid? Is there any way I can do this in xaml?
When I was need to check something like this, I was using FormattedText class, where I could get width.
I was trying to do this with property ActualWidth of TextBlock, and it work, but when Trigger changed text to "5 items selected", ActualWidth was changing and we get loop, so checking for TextBlock width need be in Event like SelectionChanged.

Skip KeyboardNavigation for all Controls in a Panel or Grid in WPF

Normaly KeyboardFocus will be skipped, when the controls IsTabStop property is set to false. But there is no such porperty for the Grid or other Panels. I tried the Attached Property KeybordNavigation.IsTabStop, but this neither had the affect of skipping the Keyboard Focus for the hole grid.
I want to skip all controls within a grid when one of the grid descendant controls will normaly reseive the focus. Has somebody experience with this an can provide an solution?
You were close. On your Grid you need to use the attached property:
KeyboardNavigation.TabNavigation="None"

Combobox dropdown not same size?

In my WPF application, I have a host window which dynamically holds usercontrols at runtime for doing the flip, fade etc. My user controls are forms with the controls like textbox, combobox etc. The dropdown's text size is not proportional to the size of the combobox. Is there any way to sort this out?
It looks like the FontSize of your ComboBox is different from the FontSize of your ComboBoxItems.
Try making both the same FontSize and see if that fixes the issue
How do you increase the size of the combobox? have you tried increasing the FontSize?
<ComboBox FontSize="16" />

Silverlight textbox with custom controls before text

How to implement textbox similar to facebook textbox in privacy settings where you can add to textbox custom controls:
One of the way that i came to is to create wrappanel where last item will be textbox.
Are there any other ways?
Thanks.
that's the only thing that comes to my mind... just have a stackpanel (wrappanel) and add items from left to right where the last one is the actual textbox...place everything in a nice canvas add some border and set the margins of the textbox to 0 so that it will fill up all the space if there is no other control in it...
it looks like it's not that big of a problem:)

WPF - Make two controls the same size

Is there any way to make two controls that are in different containers the same size in WPF? For example, suppose you have two textboxes: textbox1 and textbox2. Textbox1 is in a grid and its size can grow and shrink when the user resizes the window. Textbox2 is in another part of the window and I need it to always have the same size as textbox1. Is there any way to do this?
Keep in mind SharedSizeGroup will not work because the textboxes are in different containers. Also, I've tried binding textbox2's height property to textbox1 and that doesn't seem to work either. Finally, I tried catching textbox1's SizeChanged event, but its Height property is always NaN for some reason.
You should bind to ActualWidth and ActualHeight members of the TextBox.

Resources