can say that I am a beginner in WPF.
I have a strange behavior of GridSplitter; the grid is divided into 5 roww.
tabbar
horizontal grid
splitter
another tabbar
a textbox (txtLog)
like code below, but when I moving the separator the txtLog moves down instead of following the previous tabbar.
XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MSCSimulator"
mc:Ignorable="d"
FontSize="14"
Title="Simulator"
Height="500" Width="800"
WindowStartupLocation="CenterScreen"
WindowStyle="ThreeDBorderWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="*" MinHeight="120" />
<RowDefinition Height="10" />
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="*" MinHeight="120" />
</Grid.RowDefinitions>
<!-- TOOLBAR -->
<ToolBarTray Margin="10,10,10,10" Width="Auto" Height="30">
<ToolBar Width="Auto" Height="30">
<Button Click="Send_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/Simulator;component/Images/play.png" Width="12" Height="12" />
<Label Padding="5,0,0,0">Invia</Label>
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" MinWidth="150" MaxWidth="220" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TreeView Width="Auto" Margin="10,0,0,0">
<TreeViewItem Header="Commands" IsExpanded="True">
<!-- APPLICATION -->
<TreeViewItem Header="Application">
<TreeViewItem Header="Simulate" MouseDoubleClick="Application_Simulate_MouseDoubleClick" />
<TreeViewItem Header="Update" MouseDoubleClick="Application_Update_MouseDoubleClick" />
</TreeViewItem>
</TreeViewItem>
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter Property="FontWeight" Value="Normal"/>
</Trigger>
</Style.Triggers>
</Style>
</TreeView.Resources>
</TreeView>
<GridSplitter Width="10"
Background="White"
VerticalAlignment="Stretch"
ResizeBehavior="BasedOnAlignment" />
<!-- JSON -->
<TextBox Name="txtJSON"
Grid.Column="2"
Background="White"
TextWrapping="Wrap"
AcceptsReturn="True"
Margin="-10,0,10,0"
VerticalScrollBarVisibility="Visible"
Width="Auto" Height="Auto" />
</Grid>
<GridSplitter Grid.Row="2"
Height="10"
ResizeDirection="Rows"
HorizontalAlignment="Stretch"
ResizeBehavior="PreviousAndNext"
Background="White"/>
<!-- TOOLBAR -->
<ToolBarTray Grid.Row="3" Margin="10,0,10,0" Width="Auto" Height="30" VerticalAlignment="Top">
<ToolBar Width="Auto" Height="30">
<Button Click="Clear_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/Simulator;component/Images/clear.png" Width="16" Height="16" />
<Label Padding="5,0,0,0">Cancella</Label>
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
<!-- LOGGER-->
<TextBox Name="txtLog"
Grid.Row="4"
TextWrapping="Wrap"
Margin="10,-10,10,10"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
Width="Auto" Height="Auto"
IsReadOnly="True">
<TextBox.Background>
<SolidColorBrush Color="#282828"></SolidColorBrush>
</TextBox.Background>
<TextBox.Foreground>
<SolidColorBrush Color="White"></SolidColorBrush>
</TextBox.Foreground>
</TextBox>
</Grid>
thanks advance
In your outer Grid, try to put the Height from * to Auto in the second RowDefinition
...
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="Auto" MinHeight="120" />
<RowDefinition Height="10" />
<RowDefinition Height="50" MinHeight="50"/>
<RowDefinition Height="*" MinHeight="120" />
</Grid.RowDefinitions>
<!-- TOOLBAR -->
...
I have a spec for an application with three columns where the central one bows in into an inverted tab shape.
I have the basics figured out:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="371*"></ColumnDefinition>
<ColumnDefinition Width="469*"></ColumnDefinition>
<ColumnDefinition Width="371*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="83*"></RowDefinition>
<RowDefinition Height="309*"></RowDefinition>
<RowDefinition Height="223*"></RowDefinition>
<RowDefinition Height="67*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Background="Transparent" Grid.Row="0"
Text="Foo" HorizontalAlignment="Center" VerticalAlignment="Center" >
</TextBox>
<Border Grid.Row="0" BorderBrush="Red" BorderThickness="0,0,0,4"></Border>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="221*"></RowDefinition>
<RowDefinition Height="171*"></RowDefinition>
<RowDefinition Height="290*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
</Grid>
<Border Grid.Row="0" BorderBrush="Red" BorderThickness="4,0,4,4" CornerRadius="50" >
</Border>
</Grid>
</Grid>
But the inverted tab border is in need of clipping about 60% of the way down. I can of course position an element on top of it but that seems like the wrong solution and I'd like to avoid it.
I've looked at the Border.Clip property but can't quite figure out how to work with it nor find much in the way of documentation. What do I need to do here?
There's a bunch of different ways you can accomplish this, some will be more appropriate for potential resizing considerations than others etc. Here's just a few potential solution examples.
<StackPanel>
<!-- added -->
<Grid Background="LightBlue" Height="100">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="2"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Grid.ColumnSpan="3"
Fill="DarkBlue"/>
<Rectangle Grid.Row="1" Grid.ColumnSpan="3"
Fill="Yellow"/>
<Border Grid.Row="1" Grid.RowSpan="2" Grid.Column="1"
Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="2,0,2,2"
CornerRadius="0,0,20,20"/>
</Grid>
<!-//-->
<Grid Background="LightBlue" Height="100">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Grid.ColumnSpan="3"
Fill="DarkBlue"/>
<Rectangle Grid.ColumnSpan="3" VerticalAlignment="Bottom" Height="2"
Fill="Yellow"/>
<Border Grid.Row="1" Grid.RowSpan="2" Grid.Column="1"
Background="DarkBlue" Margin="0,-2,0,0"
BorderBrush="Yellow" BorderThickness="2,0,2,2"
CornerRadius="0,0,20,20"/>
</Grid>
<!-- Or another, or another, or another... -->
<Grid Background="LightBlue" Height="100">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="3" Height="50"
VerticalAlignment="Top" Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="0,0,0,2"/>
<Border Grid.Column="1" Height="80" CornerRadius="20"
VerticalAlignment="Top" Background="DarkBlue" BorderThickness="2,0,2,2">
<Border.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="DarkBlue" Offset="0.6"/>
<GradientStop Color="#FFFFFF00" Offset="0.6"/>
</LinearGradientBrush>
</Border.BorderBrush>
</Border>
</Grid>
<Grid Background="LightBlue" Height="100">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Height="80" CornerRadius="20"
VerticalAlignment="Top" Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="2,0,2,2"/>
<Border Grid.ColumnSpan="3" Height="50"
VerticalAlignment="Top" Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="0,0,0,2"/>
<Rectangle Grid.Column="1" Height="51" Margin="2,0"
VerticalAlignment="Top" Fill="DarkBlue"/>
</Grid>
<Grid Background="LightBlue" Height="100">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="3" Height="50"
VerticalAlignment="Top" Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="0,0,0,2"/>
<Border Grid.Column="1" Height="80" CornerRadius="20"
VerticalAlignment="Top" Background="DarkBlue"
BorderBrush="Yellow" BorderThickness="2,0,2,2"
Clip="M0,47.7 L175,47.7 L175,80 L0,80 z"/>
</Grid>
</StackPanel>
CornerRadius has a constructor that can take 4 values for the radius of each corner: top-left, top-right, bottom-right, bottom-left.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="9*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Background="Transparent" Grid.Row="0" Grid.Column="0"
Text="Foo" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border Grid.Row="1" Grid.Column="1" BorderBrush="Red" BorderThickness="4,0,4,4" CornerRadius="0, 0, 50, 50" />
</Grid>
Another option (probably the one I would choose) is to use a TabControl, put the tab on the bottom and center it.
<TabControl TabStripPlacement="Bottom" Background="DarkBlue" BorderBrush="Yellow" Margin="3" >
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</TabControl.Resources>
<TabItem Header="Test" Background="DarkBlue" BorderBrush="Yellow" Foreground="Yellow" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Grid.Row="1" Text="Foo" />
</Grid>
</TabItem>
</TabControl>
I have this XAML and having problems with grid width.
<DataTemplate x:Key="FormTileItemTemplate">
<Grid Height="70" Background="#FFECECEC">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="38" />
</Grid.ColumnDefinitions>
<StackPanel Margin="10,0,20,15" VerticalAlignment="Bottom">
<TextBlock Text="{Binding FormName}" Foreground="Black" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="0" FontSize="34.667" FontWeight="Light" LineHeight="32" />
</StackPanel>
<Grid Grid.Column="1">
<Image Stretch="UniformToFill" Source="/Assets/Images/FormCompleteRed.png" />
</Grid>
</Grid>
</DataTemplate>
<Grid x:Name="itemFormsGrid" Margin="0,60,0,50">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0,0,20,0" Width="100" Height="100" Source="/Assets/Images/session-forms.png" Stretch="UniformToFill" HorizontalAlignment="Right" />
<ListView
x:Name="formListView"
Grid.Row="1"
IsSwipeEnabled="False"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource FormTileItemTemplate}"
d:DataContext="{Binding Path=SessionForms, Source={d:DesignInstance Type=SampleData:SessionReviewDesignDataSource, IsDesignTimeCreatable=True} }"
Margin="0,20,0,0" />
</Grid>
Here is the output. Output
But I need the TextBlock to stretch way up to right. Appreciate any help.
Set HorizontalContentAlignment property like below to stretch the ListViewItems
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
I try to add GanttView to the ChildWindow and get the Error HRESULT E_FAIL has been returned from a call to a component.
I did not do anything, just add the GanttView control, below is my code.
<controls:ChildWindow.Resources>
<viewmodel:ISizeConvertr x:Name="SizeConvertr"/>
<viewmodel:IDateTimeConvertr x:Name="DateTimeConvertr"/>
</controls:ChildWindow.Resources>
<controls:ChildWindow.DataContext>
<viewmodel:PlanningInfoGanttWindowModel x:Name="planningInfoGanttWindowModel"></viewmodel:PlanningInfoGanttWindowModel>
</controls:ChildWindow.DataContext>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="DataLoadCommand"></i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<Grid x:Name="LayoutRoot" Margin="2" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="35"/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<sdk:TabControl Grid.Column="0" Grid.ColumnSpan="6" Grid.Row="3" MinHeight="300">
<sdk:TabItem Header="Plans">
<Border Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="6" Margin="2,5" Style="{StaticResource CornerBorderStyle}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"></ColumnDefinition>
<ColumnDefinition Width="1*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<telerik:RadGanttView ></telerik:RadGanttView>
</Grid>
</Border>
</sdk:TabItem>
</sdk:TabControl>
</Grid>
</ScrollViewer>
Someone Help me?
I want to decorate some controls in groups like:
<UserControl x:Class="Infrastructure.UI.ItemsGroup" ... >
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Background="Red">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" />
<TextBlock x:Name="ctrlGroupText" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>
</Border>
</UserControl>
And use it in other XAML-files like:
<Grid Grid.Column="0">
<UI:ItemsGroup GroupText="Hello World">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button>1111</Button>
<Button>1111</Button>
</Grid>
</UI:ItemsGroup>
</Grid>
But it doesn't work. What did I wrong? :)
Thanks
You need to edit the Template for the UserControl instead of adding the Border as the Child
<UserControl x:Class="Infrastructure.UI.ItemsGroup" ... >
<UserControl.Template>
<ControlTemplate TargetType="{x:Type UserControl}">
<Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Background="Red">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" />
<TextBlock x:Name="ctrlGroupText" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</UserControl.Template>
</UserControl>
Update
To set the Text for the TextBlock to GroupText you can use a Binding
<TextBlock x:Name="ctrlGroupText"
Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ItemsGroup}},
Path=GroupText}"
Grid.Row="1"
HorizontalAlignment="Center" />