VisualBrush Visual Refresh Problem - wpf

I have a grid with two rows.
In the first row, I have a rectangle, fixed width and height, whose fill is a VisualBrush whose Visual binds to a tabcontrol's selecteditem.content, which resides in the grid's second row.
All works well - the rectangle displays a scaled down version of the SelectedItem's content in the TabControl. The problem is if I remove the current TabItem and add a different one, the preview doesn't change.
Any thoughts?
Chris

Related

WPF Ellipse why can I not add a grid?

I have a WPF application. I am trying to create a ellipse toggle button. I wanted to have a textbox in the ellipse with two images next to each other below the textbox. In my other buttons I have added a grid with two rows to achieve this.
However it doesn't like it when I try to add a grid to an ellipse. "The type ellipse does not support direct content". What does this mean? Is it possible to do what I wish?
This particular error really couldn't be too much clearer:
The type Ellipse does not support direct content.
The Ellipse Shape is not a ContentControl. Therefore, it does not have a Content property. This means that you cannot add any content to it.
What you can do is to add a Grid with no columns or rows defined and add your Ellipse into the Grid. Then you can overlay other UI elements in front of the Ellipse, which may appear as if they were inside it.

WPF: Set Control Height to Fill Grid Row Height

A WPF Grid control with 3 row and 3 columns. The Height of the Row in question is set to Auto. In the first two cells I have two controls with dynamic heights. In the third cell, I have another control I want to be automatically set to stretch within the Grid cell. I have tried VerticalAlignment="Stretch", but that simply sets Grid Row Height equal to control's height. What are my options here?
Not sure what kind of control you are using in Cell 3, but most of the WPF controls will automatically stretch to fit inside the Grid cell. The row height of your grid will be set by the height of the controls in Cells 1 and 2.
If you are using some kind of custom control where the default behavior for height is different, you can set Height="Auto".
If that doesn't work either, you can do a data binding to get the actual height of the control in either cell 1 or 2. Set the Height property of your control in Cell 3 to the following:
Height="{Binding ActualHeight, ElementName=MyControlNameFromCell1, Mode=OneWay}"
EDIT
Another way that might be more robust is to do a data binding for the Height of the row. So instead of using "Auto" for the height of the row, use the data binding shown above.

Autosizing ReportViewer in WPF?

I am designing a RDLC report in WPF. Naturally I am using WindowsFormsHost to host a ReportViewer object to display the report. However, since the length of the report, specifically, the height, of the report varies each time the report is calculated and rendered depending on the actual content of the report, I want the control can adjust the size of the ReportViewer object. How can I do that? Currently I set the height of WindowsForsHost object as Auto. But that only takes effect at the first time when the WPF page is loaded, when no report is actually displayed(We need the user to input some parameters for the report and then click to calculate the report). And whenever the new report is displayed, the size of the object is not changed any more.
Thanks!
I'm not sure I got your Problem right. Maybe this helps:
You can bind the Width and Height of a control to the width and height of an other control.
For Example by defining the type of the first parent element that has the right width, here a grid:
Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType=Grid}, Path=ActualWidth"}
or by the name of the element:
Width="{Binding ElementName=MyElement, Path=ActualWidth}"
ActualWidth is the current width of the element, if the width of MyElement changes, the width of the bound element changes too. Same for the Height property.

WPF - getting the REAL width of a control

I want to set the MinWidth of a Grid ColumnDefinitions to the ActualWidth of a DataGrid inside it.
The main problem is the DataGrid has a (built-in) vertical scroller since its contents are many. So, the actual width is the size of its columns and some more, but not including the scroller.
What happens is that when I set the MinWidth, I get the rightmost column hidden behind the scroller.
I appreciate solving this both in the code and the XAML (just in order to learn).
Try putting the DataGrid into a Canvas and bind to the ActualWidth property of that instead.

WPF, ShowGridLines equivalent for wrap panel

I need to display a 1 pixel wide border around all wrap panel cells, kinda like excel grid. Unfortunately the wrap panel does not implement the grid ShowGridLines property. I can't put a border inside every cell because adjacent cells will have a 2 pixel border instead of 1 pixel.
Since the wrap panel arranges it's layout dynamically and does not expose it's properties I can't evaluate the correct value for a border inside a cell. Any workaround possible?
There is no way to show grid lines because it's just not a grid. Even in a WPF grid control, you have very little control over the appearance of lines: How can I change the color of the gridlines of a Grid in WPF?. They're really just for debugging. The workaround is to put a border inside each cell that only has thickness on the bottom and on the right: BorderThickness="0,0,1,1"

Resources