How to adjust the height of the window dynamically in WPF? - wpf

I have a model window that contains expander control.
This expander control when expanded shows the user control which allow user to enter input through textboxes.
When expander control is collapsed it hides the user control.
I want when expander is collapsed or expanded the window will resize its height accordingly at run time.
Pleas help!!

You can set property SizeToContent="WidthAndHeight", see also on SizeToContent on MSDN

Related

How to set the Scrollbar according to the inner control

I am having a user control which is to be hooked into main window at run time. So, this user control gets some width and height in the main window.
Now, this user control is having an expander control and on the click of expander some other sub user control is shown to the user and these sub user controls would be of different width and height.
So, like when a small sub user control is to be shown on the click of the expander, then control would be shown in correct manner but if the sub user control's size is large then the main user controls width or height, then we have to scroll down to see the full view of the sub user control.
Now what I want that if sub controls size is more than user controls size, then by default full view should be shown, so as I have to set the scroll bar on the click of expander.
So, How I would set the scrollbar vertically according the size of sub user control in the XAML part

WPF combobox in a dialog window - can not select items falling beyond height of window

I have a dialog window in WPF with a ComboBox. When the ComboBox items are more, they show beyond the height of the parent dialog window (in open state).
I am not able to select these items with the mouse (which are falling outside parent dialog window).
One possible solution is to increase height of the parent dialog window, but it doesn't look good.
Can someone help?
Try setting MaxDropDownHeightof your ComboBox
<ComboBox MaxDropDownHeight="100" />

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"

Why Popup part of combobox is resizable in one context and not in the other?

I have a wpf cusotm control derived from combobox System.Windows.Controls.ComboBox the control template is redefined and the popup (PART_Popup) contains a DataGrid and some other control. I use it in two places - in TabControl(,Grid) and in a Window(Grid,,Grid). When the DataGrid is resized either by dragging columns or from code the behavior is different: in window the Popup resizes in TabControl Popup remains the same and a scrollbar appears if necessary.
I need to know what can cause such difference.
Edit
Datagrid is has HorizontalAlignment="Stretch"
I find it. By mistake there was
Popup.Width=Me.Width
instead of
Popup.Width=Me.ActualWidth
This caused resizability in case when the Me.Width was not set.

mouse click event on Tab header in Tabcontrol

I have my TabControl made in WPF with C#. But I display the window like a bar by using window position. I mean while displaying only tabheader will be display. My tab header are in the left side. When I press the tabheader the window width will increse to fit the tab items content.
So I want the click event of tab headers in tabcontrol. How can I get that?
Two options:
Set the window to auto size to it's content using the Window property: SizeToContent
Use the TabControl event: SelectionChanged

Resources