Silverlight Panels - silverlight

I currently have two panels with controls on my page and when i set the top to hidden and bottom panel to visible the bottom panel is hovering down the middle of the page.
Is there a way to set this / use another control so that the 2nd panel will go to the top of the page.
thanks

<StackPanel>
<local:MyPanel1 Width="300" Height="100" Visibility="Collapsed" />
<local:MyPanel2 Width="300" Height="100" />
</StackPanel>
You can set the panels' visibility in codebehind, or better, databind it to your ViewModel (possibly using a ValueConverter to convert to the Visibility enum).

Related

Display Control from MainWindow ontop of View

Is it possible to take a control that is created in the Mainwindow and when switching views... make its zindex topmost to display over top of the view?
I tried playing with ZIndex but had no luck.
ZIndex is a Canvas property, so it won't work for other panel types like Grid, etc. If you need it to appear on top, you could have the control inherit from or placed inside a Popup.
Alternatively, if you add it at the very bottom of the main window's XAML, then it should render on top.
you have to tried DockPanel.
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Top"
Background="OliveDrab"
Foreground="Cornsilk"
FontFamily="Veranda"
FontSize="20"
TextAlignment="Center">
</DockPanel>

Unable to get vertical scroll bars in an WPF TextBlock

I'm presenting text in a wpf TextBlock control (.Net 3.5). The content of the textblock varies depending on what the user selects in a list box. The text wraps, so I don't need an horizontal scroll bar. However, there is often more text than the amount the window can display, so I need a vertical scroll bar.
As I started searching I quickly found that the answer is to wrap the TextBlock in a ScrollViewer. However, It Does Not Work (TM) and I'm hoping someone can help me work out why.
This is the structure of the UI code:
<Window x:Class=..>
<StackPanel>
<ListBox HorizontalAlignment="Stretch"
VerticalAlignment="Top" Height="200"
SelectionChanged="listbox_changed" SelectionMode="Single">
</ListBox>
<Button Click="Select_clicked">Select</Button>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<TextBlock Name="textblock" TextWrapping="Wrap"/>
</ScrollViewer>
</StackPanel>
</Window>
When the user selects an item in the list box, some text associated with this item is presented in the TextBlock. I would have thought that the code as it stands should have been all that's required, but it never provides me with a scroll bar.
Searching and experimenting have given me two clues: the root of the problem might be related to me updating the content of the TextBlock dynamically, and that the TextBlock does not resize itself based on the new content. I found a posting that seemed relevant that said that by setting the Height of the TextBlock to its ActualHeight (after having changed its content), it would work. But it didn't (I can see no effect of this).
Second, if I set the height (during design time) of the ScrollViewer, then I do get a vertical scroll bar. For instance, if I set it to 300 in the xaml above, the result is almost good in that the window as first opened contains a TextBlock with a vertical scroll bar when (and only when) I need it. But if I make the window larger (resizing it with the mouse during runtime), the ScrollViewer does not exploit the new window size and instead keeps its height as per the xaml which of course won't do.
Hopefully, I've just overlooked something obvious..
Thanks!
Because your ScrollViewer is in a StackPanel it will be given as much vertical space as it needs to display it's content.
You would need to use a parent panel that restricts the vertical space, like DockPanel or Grid.
<DockPanel>
<ListBox DockPanel.Dock="Top" HorizontalAlignment="Stretch"
VerticalAlignment="Top" Height="200"
SelectionChanged="listbox_changed" SelectionMode="Single">
</ListBox>
<Button DockPanel.Dock="Top" Click="Select_clicked">Select</Button>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<TextBlock Name="textblock" TextWrapping="Wrap"/>
</ScrollViewer>
</DockPanel>

PopUp in Silverlight is not being clipped by container control

Simple, yet frustrating issue here...
I have a PopUp control.
It is contained in side a Grid, which has a Grid.Clip defined.
The PopUp is still visible outside the Grid's clipped area.
i.e.
<Grid Background="Red" Width="150" Height="150">
<Grid.Clip>
<RectangleGeometry Rect="0,0,150,150" />
</Grid.Clip>
<Popup IsOpen="True" Margin="100,100,0,0">
<Grid Background="Green" Width="150" Height="150" />
</Popup>
</Grid>
Ideally, the green box should not appear or "bleed" outside of the red box. The problem is that it is contained within a PopUp, and so it bleeds. How can I modify this (without removing the PopUp control) so that the PopUp does not bleed outside of it's containing control?
Popup works differently. It "ignores" its parent and it is added directly into visual root of your app. This is how it can be on-top of everything.
So now it depends on what are you trying to do. I think popup is not suitable for this scenario.
You can try to clip the popup in its template, but I feel that's not what you want.

WPF <StatusBar> is not positioned at the bottom of the window

We have a WPF executable that creates a and then dynamically loads several assemblies. Each assembly represents a screen (.xaml) that is displayed in one of the tabs. The Problem is that the is right under the and not at the bottom of the window. How do I force the to always be at the bottom of the
window? Thx!
UserControl
DockPanel
CheckBox
StatusBar
DockPanel
UserControl
In addition to ArsenMkrt's answer about including the DockPanel.Dock="Bottom" attribute, don't forget that the LAST element in a DockPanel will fill the area unless you explicitly tell it otherwise using a height command (regardless of the DockPanel.Dock attribute provided).
my suggestion is to do thus:
<UserControl>
<DockPanel>
<StatusBar DockPanel.Dock="Bottom" />
<CheckBox />
</DockPanel>
</Usercontrol>
I had the same problem just now. Thanks to Stephen Wrighton's tip that the last element added to a DockPanel fills the area left over, I figured out how to set up my Window. It was a bit weird since I added the Grid last but it was positioned in the middle.
<Window>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
</MenuItem>
</Menu>
<StatusBar DockPanel.Dock="Bottom">
<StatusBarItem Content="Filler" />
</StatusBar>
<Grid x:Name="rootGrid">
</Grid>
</DockPanel>
</Window>
Did you try?
<StatusBar DockPanel.Dock="Bottom" ... />
In my case adding DockPanel.Dock="Bottom" was not enough I was forced to add VerticalAlignment="Bottom" as well.
<StatusBar DockPanel.Dock="Bottom" VerticalAlignment="Bottom" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0"/>
<StackPanel Grid.Row="1">
<StatusBar>Status Text</StatusBar>
</StackPanel>
If a StatusBar control in WPF is not positioned at the bottom of the window, there are several potential causes for this issue:
The StatusBar is not placed inside the bottommost container of the window: Make sure the StatusBar is inside the bottommost container of the window, such as a Grid or StackPanel, and that it is placed in the last row of the container.
The container's vertical alignment is not set to "Bottom": Ensure that the container that holds the StatusBar has its VerticalAlignment property set to "Bottom".
The window's height is not being set correctly: Make sure that the window's height is being set correctly, and that it is large enough to accommodate the size of the StatusBar.
The layout of the window is not correct: Check that the layout of the window is correct and that all elements are positioned correctly. You can use the Snapping and Guides feature of the Visual Studio Designer to align elements correctly.
The window is using a template that does not include the StatusBar, if you are using a custom template for the window, check that it includes the StatusBar and that it is positioned correctly.
By troubleshooting these potential causes, you should be able to resolve the issue and position the StatusBar at the bottom of the window.
In my case the order of how I put the children into the Dockpanel had an influence. So, this was the correct order to fill proberly:
<Button DockPanel.Dock="Top" Height="50">Top</Button>
<Button DockPanel.Dock="Bottom" Height="50">Bottom</Button>
<Button DockPanel.Dock="Left" Width="50">Left</Button>
<Button DockPanel.Dock="Right" Width="50">Right</Button>

Scrollbar in Listbox not working

I have a ListBox that displays a list of WPF controls.
My problem is that the vertical scrollbar is show but is disabled even when there are enough items that the ListBox should be scrollable.
One other possibly relevant fact is that this is contained in an Integration.ElementHost.
WPF noobie, Jim
Here is the XAML for the ListBox:
// for brevity I removed the Margin and Tooltip attributes
<Grid x:Class="Xyzzy.NoteListDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Name="stackPanel" Orientation="Vertical"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<StackPanel Orientation="Horizontal">
<CheckBox Name="AllRecent" IsChecked="False" >View All Recent</CheckBox>
<CheckBox Name="AscendingOrder" IsChecked="False">Descending Order</CheckBox>
<Button Name="btnTextCopy" Click="btnCopyText_Click">Copy All</Button>
</StackPanel>
<ListBox Name="NoteList"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
</ListBox>
</StackPanel>
</Grid>
And the XAML for the control displayed in each ListBox item:
<UserControl x:Class="Xyzzy.NoteDisplay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Name="Heading" FontSize="10">Note Heading</TextBlock>
<Button Name="btnCopyText" Height="20" FontSize="12"
Click="btnCopyText_Click">Copy
</Button>
</StackPanel>
<TextBlock Name="Body" FontSize="14">Note Body</TextBlock>
</StackPanel>
</Grid>
</UserControl>
I have had problems with scroll bar visibility when using a StackPanel. I think it is because the StackPanel is always as big as it needs to be to contain all of its children. Try reorganizing the layout to remove the StackPanel (use a Grid instead) and see if that helps.
You just need to introduce Height property, like this:
<ListBox Height="200"
Name="NoteList"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible">
</ListBox>
Heya, I suspect what might be happening is that your ListBox is expanding enough for every item however the ListBox is actually disappearing off the bottom of the Containing Control.
Does the ListBox actually stop properly or does it just seem to disappear? Try setting a MaxHeight on the ListBox and see if that makes the scrollbar appear. You should be able to set the VerticalScrollBarVisibility to Auto to have it only appear when needed.
If the list box is inside a StackPanel, try these steps for your ListBox
Set ScrollViewer.VerticalScrollBarVisibility="Auto"
Setting the Height property of a ListBox to some height that you expect to see.
That should force the scroll bar to show up.
This is pretty late, but anyone using ListBox probably shouldn't have it in a StackPanel. Once I switched the parent control of my Listbox from StackPanel to DockPanel with LastChildFill=True (Where the listbox was the last control), my scrollbar worked perfectly.
Hope this helps someone who's problem was not solved by the above answer.
Another solution to this problem that works well is to put a ScrollViewer around the StackPanel.
Another solution with a modification to Dave's is to use the ScrollViewer only. You only be able to scroll by placing your mouse on the ScrollView's ScrollBar. I use it this way because I don't like how ListBox jumps from item to item and sometimes missing items from the Top. Little bit hard on the eyes too. I like ScrollViewer's smooth scrolling.
I just ran into the same issue, and here's a little code demo on code project that visually shows it.
(If you want to save yourself the time of writing the code to see the differences yourself :) )
http://www.codeproject.com/Tips/659066/ListBox-and-Panels-in-WPF

Resources