Wpf Grid with 2 Rows width sizing - wpf

I am trying to work on this WPF design and not having any luck
This is the xaml
<UserControl x:Class="namespace.myuserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
Loaded="UserControl_Loaded"
Focusable="True"
d:DesignHeight="10000" d:DesignWidth="1049">
<UserControl.Resources>
<CollectionViewSource x:Key="DocumentGroup" Source="{Binding docs}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="type.Name"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<DataTemplate x:Key="groupingHeaderTemplate">
<Label VerticalAlignment="Center" Content="{Binding}" FontWeight="Bold" Background="AliceBlue"></Label>
</DataTemplate>
</UserControl.Resources>
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch" Focusable="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500" ></ColumnDefinition>
<ColumnDefinition Width="6"></ColumnDefinition>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"
BorderBrush="DarkSlateGray" BorderThickness="1" Width="6" ShowsPreview="True" >
<GridSplitter.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FF808385" Offset="0"/>
<GradientStop Color="#FFECF1F7" Offset="1"/>
</LinearGradientBrush>
</GridSplitter.Background>
</GridSplitter>
<ScrollViewer >
<ListBox Grid.Column ="0" ScrollViewer.VerticalScrollBarVisibility="Visible" Name="lstCustomList" ItemsSource="{Binding Source={StaticResource DocumentGroup}}"
SelectionChanged="ShowDocument" >
<ListBox.GroupStyle>
<GroupStyle HeaderTemplate= "{StaticResource groupingHeaderTemplate}" />
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
<Label Name="clLabel" Height="10000" Content="{Binding docResult, UpdateSourceTrigger=PropertyChanged}" Foreground="Red" Padding="5" Grid.ColumnSpan="2" Margin="0,0,7,0">
<Label.Style>
<Style TargetType="Label">
<Setter Property="Visibility" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding docs.Count}" Value="0">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<ScrollViewer Grid.Column="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch" Focusable="True">
<Grid.RowDefinitions>
<RowDefinition Height="50" ></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Width="300" Height="100">Launch</Button>
<wpf:WebView2 Grid.Row="1" Name="View2" />
</Grid>
</ScrollViewer>
</Grid>

The button is not visible because you set row height to 50 but also button height to 100. I would set row height to Auto in this case.
White space on the right side in the second column is due to you've set main grid HorizontalAlignment to Left. Just remove it.
WebView2 doesn't fill the space because the parent grid has HorizontalAlignment set to Left.
Here is updated xaml (main grid only)
...
<Grid VerticalAlignment="Stretch" Focusable="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500" ></ColumnDefinition>
<ColumnDefinition Width="6"></ColumnDefinition>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" Grid.RowSpan="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"
BorderBrush="DarkSlateGray" BorderThickness="1" Width="6" ShowsPreview="True" >
<GridSplitter.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FF808385" Offset="0"/>
<GradientStop Color="#FFECF1F7" Offset="1"/>
</LinearGradientBrush>
</GridSplitter.Background>
</GridSplitter>
<ScrollViewer >
<ListBox Grid.Column ="0" ScrollViewer.VerticalScrollBarVisibility="Visible" Name="lstCustomList" ItemsSource="{Binding Source={StaticResource DocumentGroup}}"
SelectionChanged="ShowDocument" >
<ListBox.GroupStyle>
<GroupStyle HeaderTemplate= "{StaticResource groupingHeaderTemplate}" />
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
<Label Name="clLabel" Height="10000" Content="{Binding docResult, UpdateSourceTrigger=PropertyChanged}" Foreground="Red" Padding="5" Grid.ColumnSpan="2" Margin="0,0,7,0">
<Label.Style>
<Style TargetType="Label">
<Setter Property="Visibility" Value="Collapsed"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding docs.Count}" Value="0">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<ScrollViewer Grid.Column="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Grid VerticalAlignment="Stretch" Focusable="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Button Width="300" Height="100">Launch</Button>
<wpf:WebView2 Grid.Row="1" Name="View2" />
</Grid>
</ScrollViewer>
</Grid>

Related

Powershell WPF style template for disabled ListBox

I have a powershell script which at some point creates a WPF form for some basic input from the user.
I have a ListBox with CheckBoxes where user selects necessary options, but it is disabled by default, and user needs to do some actions before it enables. As you can see from below XAML, the overall design is dark, so default disabled styling for ListBox looks pretty ugly. How do I need to change below XAML, so that when disabled, I can control at least the background? I know that I need to create a style template and add trigger that switches styles when ListBox is disabled, but I tried several approaches found online and none of them work.
Here's the XAML I'm using
<Window x:Name="MyLittleFormMainWindow" x:Class="MyLittleForm.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:MyLittleForm"
mc:Ignorable="d"
Title="My Little Form" Height="450" Width="800" FontFamily="OCRB" FontSize="14" Opacity="0.8" Background="#33000000" Foreground="Lime" BorderBrush="#05000000" WindowStyle="ToolWindow" BorderThickness="0" ResizeMode="NoResize">
<Grid Margin="0,10,4,0">
<Grid.RowDefinitions>
<RowDefinition Height="33*"/>
<RowDefinition Height="173*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="18*"/>
<ColumnDefinition Width="61*"/>
</Grid.ColumnDefinitions>
<Button x:Name="buttonGetFiles" Content="Press to enable" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="160" Height="48" Background="#F2323232" Foreground="#FFFDA100" FontSize="18" Grid.Column="0" Grid.Row="0"/>
<ListBox x:Name="checkBoxList" HorizontalAlignment="Left" Margin="10,10,10,10" VerticalAlignment="Top" Width="160" Height="200" ItemsSource="{Binding MyItemsListProperty}" SelectionMode="Multiple" Background="#F2323232" Foreground="#FFFDA100" Grid.Column ="0" Grid.Row="1" IsEnabled="False" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="2">
<CheckBox IsChecked="{Binding isChecked}" BorderBrush="#FF000A64" Background="Lime" Foreground="Lime" Content="{Binding Content}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label x:Name="textLabel" Content="My Little Form" Grid.Column="1" Grid.Row ="0" HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Top" FontFamily="OCR A Extended" FontSize="42" Foreground="Lime" Height="48" />
</Grid>
</Window>
You have to define a style for ItemsPanelTemplate of the ListBox only.
Try this one as an example:
<Grid Margin="0,10,4,0">
<Grid.RowDefinitions>
<RowDefinition Height="33*"/>
<RowDefinition Height="173*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="18*"/>
<ColumnDefinition Width="61*"/>
</Grid.ColumnDefinitions>
<Button x:Name="buttonGetFiles" Content="Press to enable" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="160" Height="48" Background="#F2323232" Foreground="#FFFDA100" FontSize="18" Grid.Column="0" Grid.Row="0"/>
<ListBox x:Name="checkBoxList"
HorizontalAlignment="Left"
Margin="10,10,10,10"
VerticalAlignment="Top" Width="160" Height="200"
ItemsSource="{Binding MyItemsListProperty}"
SelectionMode="Multiple"
Foreground="#FFFDA100"
Grid.Column ="0" Grid.Row="1"
IsEnabled="False" >
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="Background" Value="#F2323232"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
<Setter Property="Background" Value="#F2323232"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.Style>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel >
<StackPanel.Style>
<Style TargetType="StackPanel">
<Setter Property="Background" Value="#F2323232"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=IsEnabled}" Value="False">
<Setter Property="Background" Value="#AA323232"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="2">
<CheckBox IsChecked="{Binding isChecked}" BorderBrush="#FF000A64" Background="Lime" Foreground="Lime" Content="{Binding Content}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label x:Name="textLabel" Content="My Little Form" Grid.Column="1" Grid.Row ="0" HorizontalAlignment="Right" Margin="10,10,10,10" VerticalAlignment="Top" FontFamily="OCR A Extended" FontSize="42" Foreground="Lime" Height="48" />
</Grid>

Alternate background color in Listview XAML

I'm using a listView based on itemTemplate.
So i need in my template to alternate the background color :
- fist row: white
- second row:gray
- third row: white
- forth: gray
this is my template:
<DataTemplate x:Key="ItemFlight" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="#28AADB" Margin="2">
<Image Source="{Binding Path=IsArrival, Converter={StaticResource BooleanToImageDisplayConverter}}" Width="30" Height="30" VerticalAlignment="Center" Margin="5"/>
</Border>
<Grid Grid.Column="1" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding FlightName}" FontWeight="Bold" Grid.Column="0" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding ArrivalOrDepartDateTime, Converter={StaticResource DateTimeConverter}}" FontWeight="Bold" Grid.Column="0" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding Terminal, Converter={StaticResource StringUpperConverter}}" Grid.Column="1" Grid.Row="0" Margin="10" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityReverseConverter}}" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding CityInfo.Name}" Grid.Column="1" Grid.Row="0" Margin="10" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding DepartureTime}" Grid.Column="1" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding CityInfo.Name}" Grid.Column="2" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityReverseConverter}}"/>
<TextBlock Text="{Binding Terminal, Converter={StaticResource StringUpperConverter}}" Visibility="{Binding Path=IsArrival,Converter={StaticResource BooleanToVisibilityConverter}}" Grid.Column="2" Grid.Row="0" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding ArrivalTime}" Grid.Column="2" Grid.Row="1" Margin="10" Style="{StaticResource MyTextBlockStyle}"/>
<TextBlock Text="{Binding Status}" Grid.Column="3" Grid.Row="0" Grid.RowSpan="2" Margin="15" Style="{StaticResource MyTextBlockStyle}" Foreground="#EA6A1E" FontSize="20" TextWrapping="Wrap" />
</Grid>
</Grid>
</DataTemplate>
How Can I do this please??
I tried this and it works for me.
<Window x:Class="TryResponses.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="clr-namespace:TryResponses"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<vm:MainWindowViewModel x:Key="MainWindowViewModel" />
</Window.Resources>
<Grid Background="LightGray" DataContext="{StaticResource MainWindowViewModel}">
<Grid.Resources>
<Style TargetType="ListViewItem">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray" />
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="system:String">
<!-- put your data template here -->
</DataTemplate>
</Grid.Resources>
<ListView ItemsSource="{Binding Items}" AlternationCount="2" />
</Grid>
I hope this will help.
Regards
Claude
You should use AlternationCount property and it works on ListBox,ListView or any other control that inherits from ItemsControl.
The property definition and two examples are included at
https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.alternationcount%28v=vs.110%29.aspx)
To view more clearly the selected lines, you can try this : (don't take care about the colors and final render, i've not spent the necessary time to make it sexy)
<Grid DataContext="{StaticResource MainWindowViewModel}">
<Grid.Resources>
<local:FalseToCollapsedConverter x:Key="FalseToCollapsedConverter" />
</Grid.Resources>
<ListView ItemsSource="{Binding Items}" AlternationCount="2" HorizontalContentAlignment="Stretch">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid x:Name="line">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl Content="{Binding .}" Margin="4" />
<TextBlock Grid.Column="1" Text="V" Margin="4" Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem, Mode=FindAncestor}, Converter={StaticResource FalseToCollapsedConverter}}" />
<Border Grid.ColumnSpan="2" Background="#5500FF00"
BorderBrush="Blue" BorderThickness="2"
Visibility="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListViewItem, Mode=FindAncestor}, Converter={StaticResource FalseToCollapsedConverter}}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter TargetName="line" Property="Background" Value="#CCCCFF" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter TargetName="line" Property="Background" Value="#CCFFCC" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
</ListView>
</Grid>

Textblock textwrapping not working

Can somebody give me an idea of why the Wrapping is not working inide these Textblocks?
I just don't know why, i changed all my stackpanels to grids to avoid the infinite space issue, but still it doesn't work...
<Border x:Name="SummaryRightSideContainerBorder" Grid.Column="1"
Margin="10,10,10,10" BorderBrush="Black"
BorderThickness="1">
<ContentControl x:Name="SummaryRightSideContainerContentControl" Content="{Binding SelectedItem, ElementName=SummaryTreeView}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type ViewModelsProject:ProjectViewModel}">
<StackPanel>
<TextBlock Text="Displaying Project DataContract stuff..." />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModelsProject:SequenceViewModel}">
<StackPanel>
<TextBlock Text="Displaying Sequence DataContract stuff..." />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModelsProject:GroupViewModel}">
<StackPanel>
<DataGrid Margin="10" AutoGenerateColumns="False"
Background="Transparent" BorderThickness="0"
CanUserAddRows="False"
CellStyle="{DynamicResource dgCellStyle}"
ColumnHeaderStyle="{DynamicResource dgHeader}"
DataContext="{Binding ElementName=SummaryTreeView,
Path=SelectedItem}"
GridLinesVisibility="None"
ItemsSource="{Binding Standards}"
Padding="0" RowHeaderWidth="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<DataGrid.Resources>
<Style x:Key="dgHeader" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<TextBlock Width="{TemplateBinding Width}"
Padding="5"
Text="{TemplateBinding Content}"
TextAlignment="Left">
<TextBlock.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#373638" />
<GradientStop Offset="1.0" Color="#77797B" />
</LinearGradientBrush>
</TextBlock.Background>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Background" Value="Green" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.0" Color="#373638" />
<GradientStop Offset="1.0" Color="#77797B" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="dgCellStyle" TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="BorderThickness" Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Standards">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding Path=StepMaster.Description}" VerticalAlignment="Center" FontWeight="SemiBold"/>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Standard: " VerticalAlignment="Top"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Standard}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Details: " VerticalAlignment="Top"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Details}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Comments: " VerticalAlignment="Top"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Comments}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/>
</Grid>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModelsProject:StepViewModel}">
<UniformGrid Rows="3">
<TextBlock Margin="10" FontWeight="DemiBold"
Text="Standards" />
<TextBlock Margin="10" FontWeight="DemiBold"
Text="Standards Details" />
<StackPanel Orientation="Vertical">
<DataGrid Margin="10" AutoGenerateColumns="False"
<Another data grid is here />
</DataGrid>
</StackPanel>
</UniformGrid>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
</Border>
Turns out the only way to make this work is to use properties directly in the DataGrid:
MaxWidth="{Binding ElementName=SummaryRightSideContainerBorder, Path=ActualWidth}" ColumnWidth="*"
MaxWidth is used so that the Datagrid itself does not exceed its container boundaries and ColumnWidth is used so that the columns use 100% of the space available in the datagrid.
Blam's answer put me in the right track to find the solution.
As an answer you need to set second column to
<ColumnDefinition Width="*"/>
so it is constrained. * mean the size of the container. Right now it is growing outside the container (screen)
first column auto is OK

Datatemplate for Tabitem doesn't cover all the tabitem space (WPF Tabcontrol)

i have a datatemplate for a tabitem in a tab control.
The datatemplate doesn't cover all the Tabitem control, the beckground is a gray or white, control default color.
The Datatemplate of the TabItem:
<DataTemplate x:Key="ClosableTabItemTemplate">
<Border BorderThickness="1" BorderBrush="Transparent" CornerRadius="4">
<!--Border to make the tab item gap from the content-->
<Border x:Name="InsideBorder" BorderThickness="3" BorderBrush="#D6EAFF" CornerRadius="4">
<!--Border for the rounded corners-->
<!--TabItem Content Grid-->
<Grid x:Name="tabItemGrid" ShowGridLines="True" Margin="0" Background="#D6EAFF">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<!--Icon Column-->
<ColumnDefinition Width="1*"/>
<!--Title Column-->
<ColumnDefinition Width="20"/>
<!--Close Button Column-->
</Grid.ColumnDefinitions>
<!--Icon of tab Item-->
<Image Grid.Column="0" Grid.Row="1" Height="18" HorizontalAlignment="Left" Source="Images/tab1.jpg"/>
<!--Title of tab Item-->
<Label Name="TabText" Grid.Column="1" Grid.Row="1" Content="TabItem" Height="23" HorizontalAlignment="Left"
Margin="4,1,0,0" VerticalAlignment="Top" FontFamily="Courier" FontSize="12" />
<!--Close button of tab Item-->
<Button Style="{DynamicResource TabButton}"
Name="button_close" Content="x"
Command="{Binding Path=CloseCommand}"
Grid.Column="2" Grid.Row="1"
Height="20" Width="20"
Margin="0,0,0,2" VerticalAlignment="Center" HorizontalAlignment="Right"
FontFamily="Courier" FontStretch="Normal" FontWeight="Bold" FontSize="14"
Visibility="Visible" ToolTip="Close"
BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Padding="0,0,0,0"
>
</Button>
</Grid>
</Border>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabItem}},Path=IsSelected}" Value="True">
<Setter TargetName="tabItemGrid" Property="Background" Value="#D6EAFF" />
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabItem}},Path=IsSelected}" Value="False">
<!--<Trigger Property="IsSelected" Value="False">-->
<Setter TargetName="InsideBorder" Property="BorderBrush">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFCCCCD0" />
<GradientStop Color="#FF526593" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="tabItemGrid" Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFCCCCD0" />
<GradientStop Color="#FF526593" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
<!--</Trigger>-->
</DataTemplate.Triggers>
</DataTemplate>
The Tabcontrol:
<TabControl Name="MainTabCtrl" Margin="0" Padding="0" BorderThickness="0" Background="Transparent"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=TabViewModels}"
ItemTemplate="{StaticResource ClosableTabItemTemplate}">
when the Xaml code of the tabitem wasn't inside a DataTemplate it worked fine - the "Transparent" of the first border did the job and no gray/white background appeared. but when i moved the code inside a DataTemplate the gray background appeared.
How do i make the background of the tabitem transparent?
I added HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" to the tabcontrol, it only narrows the gray area a bit but it still exsits.
Try to set Padding for TabItems to zero.

<ColumnDefinition Width="*" /> not respected in DataTemplate

I have a WPF ListBox with a defined DataTemplate. In that template, I have a grid, where the first column width should take up all remaining room in the grid.
This seems to work outside the ListBox, but not inside. Why is that, and how can I get it to behave the same?
Here is my code. See line 36, and line 70
<UserControl x:Class="Russound.Windows.UI.UserControls.MAX.Reports.UniversalReportsWpf"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="250" Width="900" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Height="35" Padding="0,3,5,0" Text="Standard Reports" HorizontalAlignment="Right" FontWeight="Bold" FontSize="20" Foreground="DarkBlue"/>
<Border Grid.Row="1">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Height" Value="20"/>
<Setter Property="Padding" Value="0,3,5,0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Foreground" Value="WhiteSmoke" />
</Style>
</Grid.Resources>
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF808080" Offset="0"/>
<GradientStop Color="#FF000000" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300*" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Report Name" FontWeight="Bold"/>
<TextBlock Grid.Column="1" Text="Last Run Date" FontWeight="Bold"/>
<TextBlock Grid.Column="2" Text="Last Ran By" FontWeight="Bold"/>
<TextBlock Grid.Column="3" Text="Secure" FontWeight="Bold"/>
</Grid>
</Border>
</Grid>
<ListBox Grid.Row="1" ItemsSource="{Binding}"
ItemTemplate="{DynamicResource reportLayout}"
VirtualizingStackPanel.VirtualizationMode="Recycling"
MouseDoubleClick="DisplaySelectedReport" Grid.RowSpan="2">
<ListBox.SelectedItem>
<MouseBinding MouseAction="LeftDoubleClick"
Command="ApplicationCommands.Open" />
</ListBox.SelectedItem>
<ListBox.Resources>
<DataTemplate x:Key="reportLayout" DataType="AdHockReport">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Padding" Value="0,3,5,0"/>
<Setter Property="Cursor" Value="Hand"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" ToolTip="Report Name" Text="{Binding Path=DisplayName}" FontWeight="Bold"/>
<TextBlock Grid.Column="1" ToolTip="Last Run Date" Text="{Binding Path=LastRunDate, StringFormat=MMM dd\, yyyy h:mm tt}" />
<TextBlock Grid.Column="2" ToolTip="Last Run By" Text="{Binding Path=LastRunBy}" />
<TextBlock Grid.Column="3" ToolTip="Secure" Text="{Binding Path=IsSecure}" />
</Grid>
</DataTemplate>
</ListBox.Resources>
<ListBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE5E5E5" Offset="0"/>
<GradientStop Color="#FF888888" Offset="1"/>
</LinearGradientBrush>
</ListBox.Background>
</ListBox>
</Grid>
</UserControl>
This is because the ListBoxItem containing the grid is sizing to content. Therefore the "remaining space" for the star-sized column to fill is only as much as the column needs.
To fix this, use the ListBox.ItemContainerStyle to set ListBoxItem.HorizontalContentAlignment to Stretch.
Try editing the ControlTemplate of ListBox and remove the scrollviewer inside that, Let it be just ItemsPresenter inside Border.

Resources