My footer is currently composed of a label and an ItemsControl. It needs to be below 2 DataGrid controls that are similar in that they both contain a fixed width column for every day in the week and the end of it (which is what the ItemsControl in the footer has totals for).
I'm trying to solve the alignment, which seems easiest to just right align the day columns. I thought I could use a DockPanel as a container and Dock=Right on the ItemsControl like below, but everything is starting on the left after the label.
<DockPanel x:Name="columnTotals" DockPanel.Dock="Bottom" >
<Label ... DockPanel.Dock="Left" Width="Auto">Grand Totals</Label>
<ItemsControl DockPanel.Dock="Right"
ItemsSource="{Binding Path=TotalTimeViewModels, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
So my primary question in this post is: why doesn't the ItemsControl actually dock to the right of it's parent container (currently also a DockPanel)?
Cheers,
Berryl
The secondary and more complicated question is how to make a footer line up with DataGrid columns. My main thought to date has been to use the fact that the last columns are always the same and their width is fixed.
I can make things line up with a StackPanel using FlowDirection=RightToLeft and 8 children labels (as opposed to one ItemsControl), but this has the disadvantages of making the XAML bloated and requires the text to be RightToLeft to reverse the container flow - it's messy and confusing to look at.
I guess the footer also could be another DataGrid, but the columns wouldn't be the same so I'd still have to solve the alignment by either working right to left as I'm doing now, or figure out what the starting point of the day columns is both initially and after a resize (I do not know how to do that).
Again, thanks for reading this and Cheers,
Berryl
This code solves the alignment problem using a DockPanel:
<DockPanel LastChildFill="True" DockPanel.Dock="Bottom" >
<ItemsControl DockPanel.Dock="Right" Width="Auto" ... />
<Label ... Width="Auto">Grand Totals</Label>
</DockPanel>
Cheers,
Berryl
Related
How to add an extra vertical scrolling space into the regular WPF DataGrid to provide an ability to scroll the last rows closer to the middle of the screen?
I've searched for the solution but the only suggestion I found is "adding empty rows to the end of the list".
The solution was pretty easy by using external ScrollViewer:
<ScrollViewer HorizontalScrollBarVisibility="Hidden">
<StackPanel>
<DataGrid ItemSource={Binding MyCollection}/>
<Rectangle Height="{Binding BottomSpace}"/>
</StackPanel>
</ScrollViewer>
I got a weird problem on my xaml, in a stackPanel.
My stackPanel contains a textbox, and a button.
This should be on the same line (if possible, depending on the text width).
The problem is :
if the stackPanel have Orientation="Vertical", the button will go to the line bellow the text.
if the stackPanel have Orientation="Horizontal" , the line will not doing any break line, so all the line will go out of my grid.
<StackPanel Name="spRemplir"
Grid.Row="2"
Grid.ColumnSpan="6"
Width="560"
Margin="5,5,5,5"
Orientation="Horizontal"
VerticalAlignment="Center">
<TextBlock FontWeight="Bold"
Text={Binding Text}
TextWrapping="Wrap"/>
<Button Name="btRemplir"
Margin="5,0,0,0"
Width="150"
Content="Remplir"/>
</StackPanel>
How can I obtain a stackPanel, that will break lines if necessary, and have a text and a button on the same line?
Update with Wrapanel thanks to Eli Arbel :
<toolkit:WrapPanel Name="spRemplir"
Grid.Row="2"
Grid.ColumnSpan="6"
Margin="5,5,5,5"
Width="560"
Orientation="Horizontal">
<TextBlock FontWeight="Bold"
Text={Binding Text}
TextWrapping="Wrap"/>
<Button Name="btRemplir"
Content="Remplir"/>
</toolkit:WrapPanel>
But, the button still on the next line, while there is enough space after the text on the same line.
Itried removing the Width on the panel, but then, there is no more wrapping...
I don't understand. Even if there is stackPanel on the same Grid, they should not disturb the wrap panel right?
Thank you.
You can try a WrapPanel from the Silverlight Toolkit. Note this panel will not allow you to stretch the items to the container width.
You should also look into removing the fixed Width of the panel.
Try using a Grid instead of a StackPanel. The problem with StackPanel is that they do not report up the Visual Tree that they are out of room. This is not a bug, it's just the way they are and it's appropriate when you need it. But I avoid them except on the innermost elements. But don't have StackPanels in StackPanels as you will lose TextWrapping/Scrolling and just have elements fall of the right or bottom of the page.
Second, make sure that your outer container is Set so that the width is Constrained. For example, in your layout root, give it one Column, and set the Width for * which means = "The available space, but not more"
Once you have your outer container constrained, then your TextBlock will wrap properly.
Greg
Consider using a WrapPanel instead stack panel: http://wpftutorial.net/WrapPanel.html
I am trying to align a textblock vertically and horizontally center in a stack panel which is there in Listview but i am only able to get text vetically center but not horizontally. Plus the text is not getting wrapped. Here is the code that i have tried:
<ListBox Name="lstTiles" Margin="12,0,-12,0" Grid.Row="1" SelectionChanged="lstTiles_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Background="{StaticResource PhoneAccentBrush}" Width="145" Height="80" Margin="8,8,0,0" Orientation="Vertical" >
<TextBlock Text="{Binding Name}" Tag="{Binding ID}" Style="{StaticResource PhoneTextNormalStyle}" FontSize="15" TextWrapping="Wrap" TextAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can i achieve text vertically, horizontally and textwrap?
It looks like since you have the orientation of the StackPanel set to Horizontal, you're putting textblocks next to each other rather than on top of each other. Since the StackPanel elements take the size of their children, you would be able to visualize this as a horizontal, side-by-side, listing of textblocks. Since each textblock takes the size of the text that is in it, you are going to see blocks that are of varying widths, so centering horizontally is going to have no effect.
You could use margins (a pain) to accomplish equal widths. I don't recommend this.
You could also put grids of a set width in the stack panel, and put the textblocks on the grid. You may be able to set the width of the textblocks to get the right effect, but I can't test this at the moment, and I don't remember if it will cause the text to stretch or not.
For text wrapping, I assume you're talking about within the textblock, and that's easy - just set the textblock's TextWrapping property to Wrap.
Try setting the HorizontalContentAlignment and VerticalContentAlignment properties on the listboxitem. I don't have my dev computer now, so I can't experiment, but here is a post that might help you: Silverlight 3: ListBox DataTemplate HorizontalAlignment. Look at both of the first two answers, and see which one might be most helpful in your situation, substituting center, of course, in place of left, top, or stretch.
I have a listbox in which I use a ListBox.ItemsPanel - WrapPanel.
<ListBox ItemsSource="{Binding Path=Applets}" Margin="10,92,10,10" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" IsItemsHost="True">
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>...
I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?
My next goal would be able to reorder/ sort the items and have the render update.
TIA
I am trying to have the wrappanel have a behavior such that the items fill in to the right as the width is made wider and wrap as needed when the window is made narrower. I have played with it but the correct combination eludes me. Does anyone have a suggestion?
The code you have is almost correct, just change the Orientation to Horizontal and it should work as you describe
My next goal would be able to reorder/ sort the items and have the render update.
You don't have to do anything special for that, it's the normal behavior of a ListBox. Just change the sort order (using ICollectionView.SortDescriptions), and the UI will reflect the changes
<ListBox Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBoxItem Name="lbiTmp3_1"><CheckBox>
<TextBlock TextWrapping="Wrap">
lkjfd gmlkdsfmlk gmdsgf kds lkjglfdjmlkg jfdsg dsgf lkhfdgs lkjds fg
</TextBlock></CheckBox>
</ListBoxItem>
<ListBoxItem Name="lbiTmp3_2">C0ucou</ListBoxItem>
<ListBoxItem Name="lbiTmp3_3">C0ucou</ListBoxItem>
</ListBox>
I have the below xaml markup, the button does not seen to stretch across the screen instead its left aligned. It is contained in a stack panel. What am I doing wrong here?
<Grid>
<ListBox Name="SideNavBar">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<Button Content="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
It illogical for a StackPanel to stretch because it's job is to place each child control in a row or a column, side by side.
I think the same thinking applies to ListBox, but I'm unable to confirm at the moment.
You've set the StackPanel alignment to stretch in your example, not the Button.
This is apparently a known issue with the ListBoxItem.
See this forum discussion...