DotNetCore 3.1 WPF grid layout manager issue - wpf

i have a slight problem with the grid layout manager in WPF, using DotNetCore 3.1. I have the following code:
<TabControl Grid.Row="4" Grid.Column="0" Margin="0,0,5,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Top">
<TabItem Header="APM ops">
<UniformGrid Rows="6" Columns="1" Margin="5,5,5,5" HorizontalAlignment="Center" VerticalAlignment="Top">
<GroupBox Name="CheckStatus" Header="Check status" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<UniformGrid Grid.Row="0" Rows="1" Columns="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button HorizontalAlignment="Left" VerticalAlignment="Center">HAC processes</Button>
<Button HorizontalAlignment="Right" VerticalAlignment="Center">Nanny processes</Button>
</UniformGrid>
</GroupBox>
<GroupBox Name="RestartProcesses" Header="Restart services" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<UniformGrid Rows="8" Columns="2" HorizontalAlignment="Center" VerticalAlignment="Top">
<CheckBox>hornetq</CheckBox>
<CheckBox>marble_supervisor</CheckBox>
<CheckBox>odb</CheckBox>
<CheckBox>offline_engine</CheckBox>
<CheckBox>mercuryAS</CheckBox>
<CheckBox>businessImpactService</CheckBox>
<CheckBox>pmanager</CheckBox>
<CheckBox>db_loader</CheckBox>
<CheckBox>marble_loader</CheckBox>
<CheckBox>schedulergw</CheckBox>
<CheckBox>marble_worker</CheckBox>
<CheckBox>wde</CheckBox>
<CheckBox>marble_matcher</CheckBox>
<RadioButton>(make a selection)</RadioButton>
<Button>Restart</Button>
<RadioButton>(make a selection)</RadioButton>
</UniformGrid>
</GroupBox>
</UniformGrid>
</TabItem>
<TabItem Header="Java VM ops"/>
<TabItem Header="Server cfg"/>
<TabItem Header="Credential cfg"/>
</TabControl>
what I get is this:
What I would like to get is something more like this, where the gap betwenn the two GroupBoxes is minimized and there is some sort of margin between the checkboxes of the second Groupbox:
However, I don't seem to be able to find the correct controls and/or properties. Thanks in advance!

I figured it out. I needed to use the Grid property, not the UniformGrid ("duh!")... I guess in retrospect, it was kind of obvious, but I apparently couldn't see the forest for the trees.

Related

Viewbox TabControl sizing gets messed up depending on font size

I have a program that lets you edit different properties so that you can edit a different control.
I'm trying to get the layout right for the editor but I can't seem to get it easily.
I have put it in a viewbox so it sizes according to the screen. This is the XAML for the editor:
<Viewbox Grid.Column="0" Grid.Row="2" VerticalAlignment="Top" HorizontalAlignment="Center">
<TabControl Background="{DynamicResource CustomOrange}">
<TabItem Header="Background" Visibility="Visible" FontSize="10">
<StackPanel>
<DockPanel LastChildFill="False">
<Label Content="Background" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Background Image" DockPanel.Dock="Left"/>
<Button Content="Find Image" DockPanel.Dock="Right"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Show Text" DockPanel.Dock="Left"/>
<CheckBox Content="Find Image" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DockPanel>
</StackPanel>
</TabItem>
<TabItem Header="Button" Visibility="Visible">
<StackPanel>
<DockPanel LastChildFill="False">
<Label Content="Background IMAGE" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Background Image" DockPanel.Dock="Left"/>
<Button Content="Find Image" DockPanel.Dock="Right"/>
</DockPanel>
<DockPanel LastChildFill="False" Margin="2">
<Label Content="Show Text" DockPanel.Dock="Left"/>
<CheckBox Content="Find Image" DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DockPanel>
</StackPanel>
</TabItem>
</TabControl>
</Viewbox>
The problem is that the first TabItem looks like this:
But because I have changed the content of the label, the second TabItem looks like this:
Now, I know there are simpler ways to do this, but the problem is I don't know for sure how many options I am implementing for the user (Width, Height, Location, Font, Background, Content etc).
I have done it before with a grid but the problem is anytime I remove an option then all of them need to be re-done so that they are all in the exact Grid.Row which is why I am using StackPanel for the rows, and I am using the DockPanel so they keep separated horizontally
Thank you!!!

Place blocks with different heights like tiles with a specific order - WPF, XAML

I just started to use WPF. I cannot find the answer for my question on google for some reason...
I want to place blocks with different heights to implement the cascading layout. I saw this answer How to appose WrapPanel items of different heights (vertically)?, but it uses the 3-rd part implementation.
My code:
<WrapPanel>
<StackPanel>
<WrapPanel>
<GroupBox Header="Block1" VerticalAlignment="Top">
<StackPanel Width="200" Height="50" Background="Gray"/>
</GroupBox>
<GroupBox Header="Block2">
<StackPanel Width="200" Height="150" Background="LightBlue"/>
</GroupBox>
<GroupBox Header="Block3">
<StackPanel Width="200" Height="25" Background="LightCoral"/>
</GroupBox>
</WrapPanel>
</StackPanel>
</WrapPanel>
When the window is at normal state, it looks ok:
But when the window was maximized, it looks so:
It should look like that:
Where to search? What to search? What can I do to implement this behavior?
Thanks a lot!
Not sure if this is what you want, but if they're all the same width (and just the height is different) just have the WrapPanel lay them out vertically. At least it'll get rid of the horizontal gap:
<WrapPanel Orientation="Vertical">
<GroupBox Header="Block1">
<StackPanel Width="200" Height="50" Background="Gray"/>
</GroupBox>
<GroupBox Header="Block2">
<StackPanel Width="200" Height="150" Background="LightBlue"/>
</GroupBox>
<GroupBox Header="Block3">
<StackPanel Width="200" Height="25" Background="LightCoral"/>
</GroupBox>
</WrapPanel>

Change tab from one tab to another tab as below scenario in Silverlight

Below is the code scenario.
<controls:TabControl x:Name="TC" Background="Black" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,8" Style="{StaticResource TabControlStyle1}" HorizontalAlignment="Left" VerticalAlignment="Center" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Padding="2">
<controls:TabItem Header="TAB1" x:Name="Tab1" Style="{StaticResource TabItemStyle2}" Foreground="#FFFDFDFD">
<Grid>
<local:UC1 x:Name="childUc1" Width="Auto" Height="Auto"/>
</Grid>
</controls:TabItem>
<controls:TabItem Header="TAB2" x:Name="Tab2" Style="{StaticResource TabItemStyle2}" Foreground="White">
<Grid>
<local:UC2 Margin="0" Width="Auto" HorizontalContentAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Grid>
</controls:TabItem>
</controls:TabControl>
Here from the second tab there is one control and from that control there is one button when user click on that button then that would change to first tab. How this possible?
Please anybody help on this issue then that would be a good.
Thanks,
I assume you are always going to have two tabs,On the click event of usercontrol, you can do like this,
TC.SelectedIndex = 0;

wpf: Buttons, Textboxes, getting cut off

I am really confused why some of my textboxes and buttons are being cut off, could someone please help me fix this problem? Thanks!!
XAML CODE
<Grid>
<TabControl>
<TabItem Name="tabHome">
<TabItem.Header>
<Label Content="Home" MouseLeftButtonDown="tabHome_Click"/>
</TabItem.Header>
<Grid>
<Button Content="Parse" Height="23" x:Name="btn_parse" Width="75" Click="buttonParse_Click" Margin="180,10,180,176"/>
<TextBox IsReadOnly="True" x:Name="txtbox_filepath" Height="25" Width="135" Margin="151,52,150,132" />
<Button Content="Reset" Height="23" x:Name="btn_reset" Width="75" Margin="180,122,180,64" Click="buttonReset_Click"/>
</Grid>
</TabItem>
<TabItem Name="tabConfig">
<TabItem.Header>
<Label Content="Configuration" MouseLeftButtonDown="tabConfig_Click"/>
</TabItem.Header>
<ScrollViewer>
<StackPanel Name="panelConfig">
</StackPanel>
</ScrollViewer>
</TabItem>
<Grid>
Screenshot
As you can see the button and the textbox is cut off in the corners.
Thank you for the help I appreciate it.
When you give a Margin value like this Margin="180,10,180,176" then it means that the control has to be placed 180 dip from Left and 10 dip from Top, 180 from Right and 176 from bottom with reference to the parent control. Your controls were clipped because of the high Margin values.
Note: dip - device independent pixels.
It is better to create RowDefinitions for Grid and place controls in separate rows with reasonable margin value as shown below.
<Grid>
<TabControl>
<TabItem Name="tabHome">
<TabItem.Header>
<Label Content="Home"/>
</TabItem.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="Parse" Height="23" x:Name="btn_parse" Width="75" Margin="10" />
<TextBox Grid.Row="1" IsReadOnly="True" x:Name="txtbox_filepath" Height="25" Width="135" Margin="10" />
<Button Grid.Row="2" Content="Reset" Height="23" x:Name="btn_reset" Width="75" Margin="10"/>
</Grid>
</TabItem>
<TabItem Name="tabConfig">
<TabItem.Header>
<Label Content="Configuration"/>
</TabItem.Header>
<ScrollViewer>
<StackPanel Name="panelConfig">
</StackPanel>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
You're explicitly setting a Height and Width for the buttons, but the values you are using are too small.
If you leave them off, the button should display correctly:
<Button Content="Parse" x:Name="btn_parse" Click="buttonParse_Click" Margin="180,10,180,176"/>
<Button Content="Reset" x:Name="btn_reset" Margin="180,122,180,64" Click="buttonReset_Click"/>
Note that you can do a better job of the layout if you design this yourself using a Grid or other container instead of using Margin, as well.
Remove the Height, Width and Margin properties.
Don't use the Visual Studio designer to create WPF UIs.
Take a look at http://wpftutorial.net/LayoutProperties.html
You have used height, Width property along with Margin property. Remove height and width property and it will work fine. Ex.
<Button Content="Parse" x:Name="btn_parse" Click="buttonParse_Click" Margin="180,10,180,176"/>

how to add transperent layer over silverlight page.?

I want to add a tranparent layer over my silverlight page.
I use a StackPanel inside a Grid to do that:
<Grid>
<!--- Here is my normal content -->
<StackPanel HorizontalAlignment="Stretch" Opacity="0.8" VerticalAlignment="Stretch" >
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Something on the overlay!"/>
</StackPanel>
</Grid>

Resources