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!!!
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>
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;
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"/>
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>