don't display content outside of border wpf - c#

I don't want to display content that is outside the border in my wpf application. Here is an image to illustrate better my point:
in that picture the blue box is the border and note that its child is a listview. I don't want to display the entire listview. I just want to display whatever is inside the blue border.
What control do I have to use in order to achive that? I am looking for some sort of a mask... Is creating a custom user control my only option?

<Border ClipToBounds="True">
<ListView .../>
</Border>

Just set ClipToBounds to true on the border and it should be cut off.

Related

InkCanvas and ZIndex

InkCanvas stores all the drawing etc in "Strokes" collection and stores all the controls in "Children".
When I draw something then create a TextBox the TextBox remains under the drawing. I can't change its zIndex to bring it forward.
Is there a way to bring the text on top?
InkCanvas is not really meant for content other than strokes. But you could add the TextBox to another Panel that is over the InkCanvas, e.g.:
<Grid>
<InkCanvas/>
<Canvas>
<TextBox/>
</Canvas>
</Grid>

WPF Facebook like scrollbar behavior using scrollviewer

I have a simple scrollviewer setup in my wpf application. Everything works fine, Now I want my scrollviewer's content should use the space of my the scollbar as well, As my scrollbar is transparent it could easily display the content.
Just like the scrollbars in facebook. Attached is the image of the output. Green Section is the content and red section is scollviewer's area.
I am using WrapPanel in my scrollviewer, this is the code snippet
<ScrollViewer x:Name="ScrollViewer1"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Hidden">
<WrapPanel x:Name="WrapPanel1" SizeChanged="WrapPanel1_SizeChanged" />
</ScrollViewer>
You have to edit the ScrollViewer's ControlTemplate which should look like the one in this page : http://msdn.microsoft.com/en-us/library/aa970847(v=vs.110).aspx
In the ScrollViewer Control Template Example, you can see that the ScrollContentPresenter is inside a Border which is inside the first row of a 2-rows Grid.
Setting the RowSpan to 2 for this Border would achieve the effect you want.

Use a border in xaml without shrinking the contents of the border

I am using a border object in xaml with a large border thickness. However need a way to prevent the contents of the border from shrinking when i increase the border thickness, I just want them to draw over it if they are near enough to the edge. Any ideas?
Don't place your content inside the border, place it "above" it instead:
<Grid>
<Border BorderThickness="20"/>
<OtherContent/>
</Grid>

Re-sizing Text According to Re-sized Container

Assume I have a re-sizable part in UI that is a standard WPF container control (in this case a Canvas) and I put some text on this Canvas. How can I re-size my text according to rendered size of my Canvas?
Viewbox will stretch a TextBlock
How to: Apply Stretch Properties to the Contents of a Viewbox
<Viewbox Grid.Row="1" Grid.Column="1" Name="vb1" Stretch="Fill" >
<TextBlock Text="tulip_farm.jpg"/>
</Viewbox>
You can simply link a method to the container resize event, that will resize the text as well (this way they are always in sync), i would offer an example but since you did not post an example, i think you undetrstand what i mean.

Way to make WPF DockPanel auto-resize based on its children's size?

Right now I have a DockPanel that contains a toolbar and BrowserWindow. When I re-size the BrowserWindow to fit content, I want that change to propagate up into the DockPanel and re-size automatically. Is there a setting for this?
So the layout of my app is essentially:
-Browser Control Class
--DockPanel
----Toolbar (docked to Top)
----Browser Window Class
------Grid
--------Menu
--------Embedded Browser
Basically I want the size that I set on my Browser Window Class to automatically re-size the DockPanel.
Before applying size to Browser Window:
After applying size to Browser Window (I want to get rid of that extra space surrounding the embedded browser):
DockPanel has a LastChildFill property that you can use. Try to play with it a little. Remember that BrowserWindow needs to be the last child in DockPanel.
I think you will also have to change something in your Grid. By LastChildFill property should be set. You are on right track at least.
Change your DockPanel to a StackPanel, put it inside a Grid, and set it's HorizontalAlignment and VerticalAlignment to Center
You might also need to play with the the Height/Width of the WebBrowser to specify the initial size
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Menu />
<WebBrowser Height="SomeValue" Width="SomeValue" />
</StackPanel>
</Grid>
Can't you specify Width="Auto"?

Categories