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" />
Related
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"?
I am using a TabControl to programmatically show or hide groups of form controls. I have implemented the technique described here and it approximately works as expected, except that there is a band approximately 1 or 2 pixels high in the location where the tab headers are normally displayed.
I have verified this by using Snoop to navigate the visual tree and observe the movement of the highlight rectangle as each element is selected. The size of the rectangle for the tab content element is fractionally smaller than that of the containing TabControl, which accounts for the extra pixels I am seeing. None of the elements that might affect this have margin, border or padding.
To achieve proper alignment with other controls, I need to eliminate this extra space, but I am not sure how. However, perhaps the question I should be asking is "is there a better way to selectively show / hide groups of controls?".
Thanks for your ideas,
Tim
I suppose the thin line is caused by the TabPanel which is still there even though all TabItems are collapsed.
However, you could change the TabControl's ControlTemplate and bind the TabPanel's Visibility to the number of tabs, like this:
<TabPanel ... Visibility="{Binding Items.Count, RelativeSource={RelativeSource FindAncestor, Type={x:Type TabControl}}, Converter={StaticResource ZeroToCollapsedConverter}}" ... />
Of course, you will have to implement a converter which converts 0 to Visibility.Collapsed and all other values to Visibility.Visible.
BTW: You can get the default ControlTemplate for the TabControl here.
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.
I have some controls added in a stackpanel programmatically. What i want to do is that i want one of the controls in this stackpanel to be placed over another control. Specifically, I want to place button over an image in this stack panel. I couldn't find zindex property in c# codebehind. Although it seems very simple problem but i am unable to find any clue to solve this problem. Anyone please......??
Try placing all your controls on Canvas. Then you can set Zindex with:
this.controlName.SetValue(Canvas.ZIndexProperty, 10d);
Only the Canvas panel supports a ZIndex property. Stackpanel doesn't because each item is placed one after the other in the panel so they shouldn't overlap each other. This can be a little annoying at times when you have animated transforms moving the items about because the previous assumption isn't actually true.
In general though if you need to place items in a visual stack the Stackpanel isn't the right place for it. Perhaps a Canvas or you could use a Grid where the oridinal position of a element determines its "zorder" in a cell.
From xaml:
<StackPanel Canvas.ZIndex="1">
</StackPanel>
Is it possible in WPF to embed a ProgressBar in the Background of a TextBox?
Yes, but there are varying levels of integration you could achieve.
The simplest way would be to host a ProgressBar and TextBox with see-through background in the same Grid:
<Grid>
<ProgressBar/>
<TextBox Background="#00ffffff"/>
</Grid>
Importantly, the background color is transparent but visible to hit testing. #00000000 would not work as expected because clicking on the TextBox would actually be clicking on the ProgressBar.
You could also retemplate the TextBox to incorporate the ProgressBar more intrinsically into its template. However, this would be of limited use unless you wrote your own control while you're at it.