I am trying to bind a TabControl to the size of the MainWindow in WPF. I have done it very easily, but the problem is with padding or margin.
If I just set the both with the same size during the window resize, then the TabControl hangs off the right side of the window by it's border. I have tried playing with padding and margin of the TabControl with no effect on it's over flow of the window.
Should I use a custom converter? My skill with them is pretty novice and am not sure how I would work a two way converter for these properties.
Related
Im writing a WPF application where usercontrols are added to a TabControl at runtime - creating a tab for each user control. The problem then is...these controls can have different width and height which means the tabcontrol must adjust its own width and height accordingly. I tought this would be a simple exercise of just accessing the usercontrols Height/ActualHeight properties, but these are NaN/0.0
Is it not possible to get this information?
I can propose next solution:
When you add a new control to the TabControl (is it a TabControl or a TabItem?) set bindings for the Width and Height properties. Create a converter to convert sizes of added controls to the size of Owner (in case if you need to have minimum size).
ActualWidth and ActualHeight properties perhaps are 0 because control wasn't measured yet. Look this thread
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.
I have a UserControl that have a storyboard that moves a control (within my UserControl) out of the usercontrol (using a TranslateX RenderTransform).
When I move the object out of the control it shows on the parent Page (that hosts my UserControl). Is there a way to just hide it when it reaches the boundaries of my UserControl?
At the end of your storyboard set the animated controls visibility to collapsed/opacity = 0. If that animation is too abrupt for you, animate the opacity to 0 as the storyboard progresses. To detect when the animation goes out of your control would be rather difficult. You're probably best off "guessing" by waiting a few tenths of a second.
You could try setting the Canvas.ZIndex so that the Control is behind the Parent Control
The Z-Index doesn't work since its outside my UserControl.
I was thinking more like using the "Clip" property, but I'm not really familiar with it :/
What I finally did :
Use a Canvas (instead of a Grid) as my LayoutRoot of my UserControl
Added a Canvas.Clip that matches the size of my UserControl
On the SizeChanged of my UserControl I resize my Clip to fit the new size.
I'd like to post the XAML here but somehow the CodeSample does not work :/ Sorry
I need to fill a Rectangle with a custom UserControl. The rectangle's .Fill property accepts a Brush and in Silverlight there is no equivalent for VisualBrush.
I've found this post - http://chriscavanagh.wordpress.com/2009/09/24/silverlight-visualbrush-and-rounded-corners/ - with a possible solution. However this approach requires the UserControl (which will be used to fill the rectangle) to be rendered first outside the rectangle so that the VisualImage can convert it to a WritableBitmapImage.
Does anyone know any alternate solution? I would prefer not having to render the user control outside the rectangle and remove it afterwards, because there is the possibility for some flickrs to occur.
Thanks and best regards,
Bruno
There is no alternate solution if you must be using a rectangle and brush for its fill.
I take it you already have a reason not to simply use a Border containing the UserControl directly? If you don't want the usercontrol to response to the mouse you could include in the Border a Grid containing both your UserControl and a Rectangle with a transparent fill.
I have a WPF UserControl (Foo.xaml) that should be displayed streched (VerticalAlignment="Stretch" HorizontalAlignment="Stretch") on a window.
If I don't specify Width/Height on the UserControl it will be displayed as intended at runtime. Unfortunately the VS WPF designer will not show the control correctly if I open Foo.xaml (size may be 0x0 depending on the child controls).
If I specify a size on the UserControl the designer will work correctly with Foo.xaml but then it won't strech at runtime.
How can I fix this so that it works at design and runtime?
It sounds like your UserControl is only useful if it is a certain minimum size. If so, set the MinWidth and MinHeight properties.
You can set the DesignWidth and DesignHeight properties on the UserControl to adjust the height and width of the control in the design view.
You can adjust those properties with the mouse by dragging the square rectangles that show up when you select the resize tool for the UserControl.