Wpf controls overlay? - wpf

I have Dockpanel on which there are two buttons (left and right sides) and a scrollviewer at the bottom. Is it possible to hide the left and right sides of this scrollviewer UNDER this buttons?

You could use a Grid instead of a DockPanel, either use the alignments or create columns and adjust the ColumnSpan, example of the latter:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Order matters, earlier controls are at the bottom unless you use Panel.ZIndex -->
<ScrollViewer Grid.Column="0" Grid.ColumnSpan="3"/>
<Button Grid.Column="0" Content="Left"/>
<Button Grid.Column="2" Content="Right"/>
</Grid>
(DockPanel is quite a poor control which can easily be replaced with a Grid in about every case)

Related

WPF puts a white gap around a label

I have a grid inside a grid, that has a label inside. When I leave the label's padding as it is, everything's fine. But when I set the padding to 0, this happens:
(There's not supposed to be a white border there)
Here's my XAML code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"></ColumnDefinition>
<ColumnDefinition Width="0.8*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.02*"></RowDefinition>
<RowDefinition Height="0.98*"></RowDefinition>
</Grid.RowDefinitions>
<Grid VerticalAlignment="Center" Margin="0px" x:Name="TitleBar" Background="#121212" Grid.ColumnSpan="2" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"></ColumnDefinition>
<ColumnDefinition Width="0.6*"></ColumnDefinition>
<ColumnDefinition Width="0.2*"></ColumnsDefinition>
</Grid.ColumnDefinitions>
<Label Padding="5px 0px 0px 0px" Grid.Column="0" Grid.Row="0" Foreground="White">WorkChatApp</Label>
</Grid>
<ScrollViewer x:Name="Channels" Background="#232323" Grid.Column="0" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"></ScrollViewer>
<ScrollViewer x:Name="Messages" Grid.Column="1" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"></ScrollViewer>
</Grid>
That is not a border, but the background of the window. You define the Grid that contains your TitleBar Grid with rows that have star-sized heights: 0.02* and "0.98*". That means, the first row will always be scaled to occupy 2% of the available height and the second row will occupy 98% of the available height.
However, you have set the VerticalAlignment of the TitleBar Grid to Center, so it will be scaled only to the size that is necessary to display its content and then centered. That also means, if there is more space than necessary, the TitleBar is centered and above and beyond it there will be empty space and that is what you see and perceive as a border. If you scale your application window up, you can observe the same effect. Consequently, this is not related to the Padding of the Label.
Setting star-sized heights in this manner can lead to bad layout or even unusable controls when resizing the parent container. For example, if you scale your window down, the TitleBar will not be readable at some point.
Instead of this, you could make the first row Auto-sized and the second star-sized (* is the default).
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.8*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- ...other grid content. -->
</Grid>
If you define the columns like this, the first row will always shrink to the minimum size that is necessary to display its content and the second row takes up the remaining space.

DataTemplate of Grid inside ListView is not resizing

I have a ListView that lays on top of UI graphics in my UserControl that I want to show and size using a Grid that matches the parent grid. I'm trying to template the way each item shown and sized using the ListView.ItemTemplate. The issue I'm having is that the DataTemplate is not sizing to the main Grid of the UI, and I'm not sure why.
This is what I've done, I think it a fairly simple and straight forward datatemplate:
<ListView ItemsSource="{Binding Path=StatusFilter}" Grid.Row="2" Grid.ColumnSpan="12">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="92"/>
<ColumnDefinition Width="90"/>
<ColumnDefinition Width="85"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Path=ECNNumber}" Grid.Column="0"/>
<Label Content="{Binding Path=DateECNDue}" Grid.Column="1"/>
<Label Content="{Binding Path=Model.Model}" Grid.Column="2"/>
<--More stuff for each column-->
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
When this is displayed the grid is completely bypassed and each element is shown like a horizontally aligned stackpanel. To test that my DataTemplate wasn't faulty I threw it into an ItemsControl and it worked perfectly. It resized with the parent grid without any issues.
Why isn't this working for the ListView, and how do I get it to work? I need the selection and scrollview capability of the ListView otherwise I'd be using the ItemsControl.
I read something about Grid.SharedSizeScope but that doesn't work with dynamic sizing of grid, and that's all I could really find on this issue.

Auto Sizing between grid columns

I have two controls and a GridSplitter .
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<UserControlOne Grid.Colum="0" Visibility="{Binding MyProperty1}"/>
<GridSplitter Visibility="{Binding MyProperty1}" m:Splitterbehaviour.Apply= true/>
<UserControlTwo Grid.Colum="1" />
</Grid>
I am trying to show/hide the UserControlOne with the MyProperty1 which is working fine but when it is hidden i want the UsercontrolTwo to take whole page space. I could easily achieve this by using a stack or dock panel. But if i use the stackpanel or dockpanel my GridSplitter wont work.(I have a behaviour set to GridSplitter which will identify the first column and it will help to resize the first and second column)
I don't see how that splitter is working
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<UserControlOne Grid.Colum="0" Visibility="{Binding MyProperty1}"/>
<UserControlTwo Grid.Colum="1"/>
</Grid>

Enable scroll bar inside text box wpf

I have a comments textbox put inside a groupbox, which occupies the whole bottom part of the screen.
I need to enable scroll bar both vertical and horizontal when the text exeeds the current size textbox .
But for me the textbox size is getting increased and scroll bar is enabled in the group box.
How shall i disable the scroll bar of the Group box and enable only the scroll bar inside textbox ?
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="{StaticResource FormWidthGridLength}" MaxWidth="{StaticResource FormColumnSpacerDouble}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- some controls here -->
<GroupBox Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="4" Header ="Comments">
<TextBox Text="{Binding Comments}" TextWrapping="Wrap" />
</GroupBox>

Resize window parts in runtime

I want to have main window split in three parts like the one on the picture. there's supposed to be a line (red one) or left border of the rectangle number 2, that, when it's dragged with mouse, it resizes both rectangle 1 and 2. it's like the behaviour of playlist in windows media player. any ideas on how to obtain this? Also, it would be great if someone proposes a solution to how this playlist make collapsed if the red line is dragged to the right.
Define a <Grid> with columns and rows like so:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="300"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="600"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
...
and then the gridsplitter (still inside the grid):
<GridSplitter Grid.Row="0" Grid.Column="1" ResizeDirection="Columns" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
Note that the gridsplitter will need it's own column.
It is a GridSplitter, here is how to use one:
<GridSplitter Grid.Row="1"
Height="5"
Width="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Gray"
ResizeDirection="Rows" />
You need to assign a Row or Column to it from your Grid, and specify its ResizeDirection. This one is horizontal, but you get the idea for a vertical one.
HTH,
Bab.

Resources