SharedSizeGroup on dataGrid - wpf

I have a DataGrid and a grid on my WPF application and I want their respected columns be the same size. I thought maybe I use SharedSizeGroup but it seems that DataGrid columns don’t have this property (Am I wrong?).
How can I do this?
Update1
I changed the xaml as follow:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" MaxHeight="20" MinHeight="20" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="{Binding ElementName=titleDataGridColumn, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=forenameDataGridColumn, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=surnameDataGridColumn, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=dobDataGridColumn, Path=ActualWidth}" />
</Grid.ColumnDefinitions>
<Button Content="Clear" HorizontalAlignment="Stretch" Name="searchClearButton" VerticalAlignment="Stretch" Grid.Column="0" Click="searchClearButton_Click" />
<TextBox HorizontalAlignment="Stretch" Name="forenameTextBox" VerticalAlignment="Stretch" Grid.Column="1" />
<TextBox HorizontalAlignment="Stretch" Name="surnameTextBox" VerticalAlignment="Stretch" Grid.Column="2" />
<TextBox HorizontalAlignment="Stretch" Name="dobTextBox" VerticalAlignment="Stretch" Grid.Column="3" />
</Grid>
<DataGrid Grid.Row="1" x:Name="DataDataGrid" HorizontalAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Stretch" ItemsSource="{Binding}" AlternationCount="1" IsReadOnly="True" SelectionMode="Single" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="titleDataGridColumn" Binding="{Binding Path='Title'}" Header="Title" Width="35*" />
<DataGridTextColumn x:Name="forenameDataGridColumn" Binding="{Binding Path='Forename'}" Header="Forename" Width="65*" />
<DataGridTextColumn x:Name="surenameDataGridColumn" Binding="{Binding Path='Surname'}" Header="Surname" Width="65*"/>
<DataGridTextColumn x:Name="dobDataGridColumn" Binding="{Binding DOB,StringFormat={}\{0:dd/MM/yyyy\}}" Header="DOB" Width="70*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
But now the surname column in grid is bigger than its corresponding column in datagrid and the button is a bit to left ( could be fixed by setting margin on grid column) but I cannot understand why surname columns are not same size?
Update 2
This is working (Problem was the surenameDataGridColumn was not correct (spelling))
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20" MaxHeight="20" MinHeight="20" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="6px"/>
<ColumnDefinition Width="{Binding ElementName=titleDataGridColumn, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=forenameDataGridColumn, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=surnameDataGridColumn, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=dobDataGridColumn, Path=ActualWidth}" />
</Grid.ColumnDefinitions>
<Button Content="Clear" HorizontalAlignment="Stretch" Name="searchClearButton" VerticalAlignment="Stretch" Grid.Column="1" Click="searchClearButton_Click" />
<TextBox HorizontalAlignment="Stretch" Name="forenameTextBox" VerticalAlignment="Stretch" Grid.Column="2" />
<TextBox HorizontalAlignment="Stretch" Name="surnameTextBox" VerticalAlignment="Stretch" Grid.Column="3" />
<TextBox HorizontalAlignment="Stretch" Name="dobTextBox" VerticalAlignment="Stretch" Grid.Column="4" />
</Grid>
<DataGrid Grid.Row="1" x:Name="DataGrid" HorizontalAlignment="Stretch" AutoGenerateColumns="False" VerticalAlignment="Stretch" ItemsSource="{Binding}" AlternationCount="1" IsReadOnly="True" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="titleDataGridColumn" Binding="{Binding Path='Title'}" Header="Title" Width="35*" />
<DataGridTextColumn x:Name="forenameDataGridColumn" Binding="{Binding Path='Forename'}" Header="Forename" Width="65*" />
<DataGridTextColumn x:Name="surnameDataGridColumn" Binding="{Binding Path='Surname'}" Header="Surname" Width="65*"/>
<DataGridTextColumn x:Name="dobDataGridColumn" Binding="{Binding DOB,StringFormat={}\{0:dd/MM/yyyy\}}" Header="DOB" Width="70*"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
By adding a new column, I aligned the left of button with the left of Title column in DataGrid.

Use binding to bind the Grid column widths to the size of the columns in your DataGrid. For example:
<dg:DataGridTextColumn x:Name="FirstColumn" Header="Text"/>
<ColumnDefinition Width="{Binding ElementName=FirstColumn, Path=ActualWidth}"/>

Related

Binding two ViewModel for two DataGrid, but only 1 DataGrid can display data

I have 2 DataGrid to display information from 2 tables I get from Database MySQL. I'm using MVVM pattern and I have 2 ViewModel called: "CheckJigInfoViewModel" and "AccessoryViewModel" for those DataGrid. I setthose ViewModel to my two DataGrid, but only one in two DataGrid can show the data.
Am I getting wrong some code? Please give me some advise!
I atttach some picture for the content above and code for my ViewModel:
The pictures:
- Code for ViewModel:
ViewModel: CheckJigInfoViewModel
class CheckJigInfoViewModel
{
PersonnelBusinessObject personnel;
ObservableCollection<CheckJigInfo> _listCheckJigInfo;
public CheckJigInfoViewModel(){
personnel = new PersonnelBusinessObject();
}
public ObservableCollection<CheckJigInfo> ListCheckJigInfo
{
get
{
_listCheckJigInfo = new ObservableCollection<CheckJigInfo>(personnel.GetListCheckJigInfo());
return _listCheckJigInfo;
}
}
}
ViewModel: AccessoryViewModel
class AccessoryViewModel
{
PersonnelBusinessObject personnel;
ObservableCollection<Accessory> _lstAccessory;
public AccessoryViewModel()
{
personnel = new PersonnelBusinessObject();
}
public ObservableCollection<Accessory> ListAccessory
{
get
{
_lstAccessory = new ObservableCollection<Accessory>(personnel.GetListAccessory());
return _lstAccessory;
}
}
}
the xaml file (AccessoryInfo.xaml):
<Window x:Class="CheckJigWPF.View.AccessoryInfo"
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:CheckJigWPF.View"
xmlns:ViewModels="clr-namespace:CheckJigWPF.ViewModels"
mc:Ignorable="d"
Title="Accessory Info " Height="569.1" Width="890">
<Window.Resources>
<ViewModels:CheckJigInfoViewModel x:Key="CheckJigData"/>
<ViewModels:AccessoryViewModel x:Key="AccessoryData"/>
</Window.Resources>
<!---MAIN GRID-->
<Grid >
<!---MAIN GRID ROWS AND COLUMNS DEFINITION-->
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<!--GROUPBOX1-->
<GroupBox Grid.Row="0" Header="Pulley checking info" Padding="0,2">
<!--SUB GRID FOR GROUPBOX1-->
<Grid>
<!---SUB GRID ROWS AND COLUMNS DEFINITION-->
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<!--GROUPBOX1's Controls-->
<TextBox Grid.Column="0" Name="txtSearch" FontSize="24"/>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button Grid.Column="1" Name="btnSearch" Width="100" Content="Search"/>
<Button Grid.Column="1" Name="btnClear" Width="100" Content="Clear"/>
</StackPanel>
<DockPanel Grid.Row="1" Grid.ColumnSpan="2">
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding ListCheckJigInfo, Source={StaticResource CheckJigData}}" ColumnWidth="*" SelectionMode="Single" IsReadOnly="True" FontSize="18" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Width="50" Binding="{Binding ID}"/>
<DataGridTextColumn Header="AUFNR" Width="200" Binding="{Binding AUFNR}"/>
<DataGridTextColumn Header="MATNR" Width="200" Binding="{Binding MATNR}"/>
<DataGridTextColumn Header="Shelf" Width="100" Binding="{Binding Shelf}"/>
<DataGridTextColumn Header="MAKTX" Width="*" Binding="{Binding MAKTX}"/>
<DataGridTextColumn Header="Qty" Width="100" Binding="{Binding Qty}"/>
<DataGridTextColumn Header="MEINS" Width="120" Binding="{Binding MEINS}"/>
<DataGridTextColumn Header="CheckStatus" Width="150" Binding="{Binding Check}"/>
<DataGridTextColumn Header="CheckingDate" Width="180" Binding="{Binding CheckingDate,StringFormat='yyyy-MM-dd HH:mm:ss'}"/>
<DataGridTextColumn Header="User" Width="100" Binding="{Binding UserID}"/>
</DataGrid.Columns>
</DataGrid>
<!--paging-->
<StackPanel Name="pager" Orientation="Horizontal">
<TextBlock Text="{Binding Page,StringFormat=Page 0 of 0}"/>
</StackPanel>
</DockPanel>
<!--End GROUPBOX1's Controls-->
</Grid>
</GroupBox>
<!--END GROUPBOX1-->
<!--GROUPBOX2-->
<GroupBox Grid.Row="1" Header="Accessory Management" Padding="5">
<!--SUB GRID FOR GROUPBOX2-->
<Grid>
<!--GROUPBOX2 ROWS AND COLUMNS DEFINITION-->
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!--GROUPBOX2's Controls-->
<DockPanel Grid.Row="0" Grid.Column="0">
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="AccessoryID" Margin="5" Padding="5" Background="#FFD7F4AA" FontSize="18"/>
<TextBox Name="txtAccessoryID" Margin="5" FontSize="20"/>
</StackPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="Accessory Name" Margin="5" Padding="5" Background="#FFD7F4AA" FontSize="18"/>
<TextBox Name="txtAccessoryName" Margin="5" FontSize="20"/>
</StackPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="Shelf" Margin="5" Padding="5" Background="#FFD7F4AA" FontSize="18"/>
<TextBox Name="txtShelf" Margin="5" FontSize="20"/>
</StackPanel>
</DockPanel>
<!--SUB GRID FOR GROUPBOX2-->
<Grid Grid.Column="1">
<!--GROUPBOX2 ROWS AND COLUMNS DEFINITION-->
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<!--GROUPBOX2's Controls-->
<TextBox Grid.Column="0" Name="txtSearchAcs" FontSize="24"/>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<Button Name="btnSearchAcs" Width="100" Content="Search"/>
<Button Name="btnClearAcs" Width="100" Content="Clear"/>
</StackPanel>
<DockPanel Grid.Row="1" Grid.ColumnSpan="2">
<DataGrid Name="dgvAccessoryInfo" ItemsSource="{Binding ListAccessory, Source ={StaticResource AccessoryData}}" AutoGenerateColumns="False" ColumnWidth="*" SelectionMode="Single" IsReadOnly="True" FontSize="18" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Acs ID" Binding="{Binding ACSID}"/>
<DataGridTextColumn Header="Acs Name" Binding="{Binding ACSName}"/>
<DataGridTextColumn Header="Acs Shelf" Binding="{Binding ACSShelf}"/>
</DataGrid.Columns>
</DataGrid>
</DockPanel>
<!--End GROUPBOX2's Controls-->
</Grid>
<!--FUNCTIONS-->
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
<Button Content="Save" Width="100" Height="40" BorderThickness="0" Background="MediumSeaGreen" Foreground="#ffffff" FontSize="24" Margin="5"/>
</StackPanel>
</Grid>
</GroupBox>
<!--END GROUPBOX 2-->
</Grid>
</Window>
I expect to show each ViewModel for each DataGrid.
Thanks in advance!
I found the answer for my problem. Thanks #Avinash Reddy for your advise. Because my sub-grid layout for the DataGrid in my GroupBox2 overflow. It drowned the GridData of GroupBox1 and I didn't see my GridData in GroupBox1 shown the data. I fixed it by to set a "Height" for the DataGrid in GroupBox2 and It's worked well.

DataGrid Column Sets with a header for each set

I wanted to create a WPF data grid which displays a certian number of column sets for each category as in the below image:
enter image description here
Can anyone help me how we can achieve this with wpf Datagrid?
You can put your DataGrid in a Grid panel and then bind its ColumnDefinitions widths to the column headers widths. Something like:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=datagrid, Path=RowHeaderWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnD, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnE, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnF, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnG, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnH, Path=ActualWidth}" />
<ColumnDefinition Width="{Binding ElementName=ColumnI, Path=ActualWidth}" />
</Grid.ColumnDefinitions>
<DataGridColumnHeader Grid.Column="1" Grid.ColumnSpan="2" Content="A" HorizontalContentAlignment="Center" />
<DataGridColumnHeader Grid.Column="3" Grid.ColumnSpan="2" Content="B" HorizontalContentAlignment="Center" />
<DataGridColumnHeader Grid.Column="5" Grid.ColumnSpan="2" Content="C" HorizontalContentAlignment="Center" />
</Grid>
<DataGrid Name="datagrid" AutoGenerateColumns="False"
Grid.Row="1" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Header="D" Width="*" x:Name="ColumnD" />
<DataGridTextColumn Header="E" Width="*" x:Name="ColumnE" />
<DataGridTextColumn Header="F" Width="*" x:Name="ColumnF" />
<DataGridTextColumn Header="G" Width="*" x:Name="ColumnG" />
<DataGridTextColumn Header="H" Width="*" x:Name="ColumnH" />
<DataGridTextColumn Header="I" Width="*" x:Name="ColumnI" />
</DataGrid.Columns>
</DataGrid>
</Grid>
My XAML does not consider header's borders, but you can easily include them by using a converter which gets the ActualWidth and sum it to the border thickness.
I hope it can help you.

Prevent content to scroll

Essentially I've a DataGrid with multiple headers, in wpf there is no control that implement this so I've implemented my own solution.
The control look like this:
[Header1 ][Header2][Header3][Header4 ]
[column 1][column2][Column3][Column4][Column5][Column6]
so as you can see under specific column I've a header that group x columns.
This is my implementation:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Width="{Binding Path=Width, ElementName=RankingsHalfTime}">
<!-- multiple headers -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ElementName=HalfColumn0, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn1, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn2, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn3, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn4, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn5, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn6, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn7, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn8, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn9, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn10, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn11, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn12, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn13, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn14, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn15, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn16, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn17, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn18, Path=ActualWidth}"/>
<ColumnDefinition Width="{Binding ElementName=HalfColumn19, Path=ActualWidth}"/>
</Grid.ColumnDefinitions>
<!-- Multiple Headers-->
<Border Grid.Column="2" Grid.ColumnSpan="6" BorderThickness="1 1 1 1" Margin="-1 0 -1 0">
<Label TextBlock.FontWeight='Bold' Background="WhiteSmoke" Content="Header 1" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Column="8" Grid.ColumnSpan="6" BorderThickness="1 1 1 1" Margin="0 0 -2 0">
<Label TextBlock.FontWeight='Bold' Background="WhiteSmoke" HorizontalAlignment="Center">Header 2</Label>
</Border>
</Grid>
<DataGrid AutoGenerateColumns="False"
CanUserAddRows="false" Grid.Column="1" Grid.Row="1"
RowStyle="{StaticResource CustomRowStyle}"
ItemsSource="{Binding RankingController.RankingsHalfTime}"
IsReadOnly="True" x:Name="RankingsHalfTime" >
<DataGrid.Columns>
<DataGridTextColumn Header="0" x:Name="HalfColumn0" Binding="{Binding Position}"/>
<DataGridTextColumn Header="1" x:Name="HalfColumn1" Binding="{Binding Team}" Width="200" />
<DataGridTextColumn Header="2" x:Name="HalfColumn2" />
<DataGridTextColumn Header="3" x:Name="HalfColumn3" />
<DataGridTextColumn Header="4" x:Name="HalfColumn4" />
<DataGridTextColumn Header="5" x:Name="HalfColumn5" />
<DataGridTextColumn Header="6" x:Name="HalfColumn6" />
<DataGridTextColumn Header="7" x:Name="HalfColumn7" />
<DataGridTextColumn Header="8" x:Name="HalfColumn8"/>
<DataGridTextColumn Header="9" x:Name="HalfColumn9" />
<DataGridTextColumn Header="10" x:Name="HalfColumn10" />
<DataGridTextColumn Header="12" x:Name="HalfColumn11" />
<DataGridTextColumn Header="12" x:Name="HalfColumn12" />
<DataGridTextColumn Header="13" x:Name="HalfColumn13" />
</DataGrid.Columns>
</DataGrid>
</Grid>
The code working pretty well, the result that I want is achieved successfully, but there is a problem:
when the window is resized, the DataGrid display an horizontal scrollbar, this will bug the logic of multiple headers, infact, when the user move the horizontal scrollbar, the multiple header doesn't keep fixed to the original position, so the final result is this (when I move the scrollbar):
[Header1 ][Header2][Header3][Header4 ]
[column 1][column2][Column3][Column4][Column5][Column6]
[scrollbar ]
I'm looking for a way to prevent multiple header scrolling and keep them to stuck at the original position. You can try my code for a better practice explanation.

Wrapping itemscontrol items in a form

Currently i have a form with this layout
Label:TextBox
Label:TextBox
.............
I have to change the layout to
Label:TextBox Label:TextBox
Label:TextBox Label:TextBox
............. .............
By vertical wrapping of items.
I have done this before with static items. But the items are in Itemscontrol thanks to the previous coder.
Here is my current code.
<Grid Background="{StaticResource AppWhiteBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="250"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="75"></ColumnDefinition>
</Grid.ColumnDefinitions>
.....................................................................
<StackPanel MaxHeight="350" Orientation="Vertical"
ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalAlignment="Top"
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Visibility="{Binding
IsEditClick, Converter={StaticResource InverseBoolToVisibilityConverter}}"
x:Name="ViewPanel" >
<StackPanel.Resources>
<DataTemplate x:Key="ContainerDetailsList">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Style="{StaticResource DetailsItemKey}"
Content="{Binding ItemLabel}">
</Label>
<TextBox Grid.Column="1" x:Name="TextItem" Text="{Binding
OriginalItemValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource DetailsItemValue}">
</TextBox>
</Grid>
</DataTemplate>
</StackPanel.Resources>
<ItemsControl x:Name="MainContainerDetails"
Visibility="{Binding DetailsMenuItemViewModel.IsSelected, Converter=
{StaticResource BoolToVisibilityConverter}}"
ITEMSOURCE="{Binding ValueItems, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource DetailsItemTemplateControl}"
ItemTemplate="{StaticResource ContainerDetailsList}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="true" Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
The items are not wrapping... what am i missing?
you should play with MaxWidth Property like this
substitue this:
<ColumnDefinition Width="*" />
with this
<ColumnDefinition Width="*" MaxWidth="100"/>

Binding conconst value to a table

Suppose I have a table 4x4, no more/less rows and columns. The values are from the calculations in the code.
What is the best way to create it and bind the data?
Using datagrid or table?
I used datagrid for columns but not sure how to deal with rows.
<DockPanel>
<DataGrid Name="dgTest" AutoGenerateColumns="False" IsReadOnly="True" CanUserResizeColumns="True" CanUserAddRows="False" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="IVR" Binding="{Binding IVR}" />
<DataGridTextColumn Header="Payment" Binding="{Binding Payment}" />
<DataGridTextColumn Header="Call" Binding="{Binding Call}" />
</DataGrid.Columns>
</DataGrid>
</DockPanel>
Edit: 10:08 am 11/03/2014
Based on the Mike's comment, I made a change.
<DockPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<TextBox Grid.Column="1">IVR</TextBox>
<TextBox Grid.Column="2">PAYMENT</TextBox>
<TextBox Grid.Column="3">CALL</TextBox>
<TextBox Grid.Row="1">SUCCESS</TextBox>
<TextBox Grid.Row="2">FAIL</TextBox>
<TextBox Grid.Row="3">TOTAL</TextBox>
</Grid>
</DockPanel>
Then how to bind the values?
Thanks Mike Strobel, I used Grid plus textboxs.
<DockPanel Margin="20">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<TextBox Grid.Column="0" />
<TextBox Grid.Column="1">IVR</TextBox>
<TextBox Grid.Column="2">PAYMENT</TextBox>
<TextBox Grid.Column="3">CALL</TextBox>
<TextBox Grid.Row="1">SUCCESS</TextBox>
<TextBox Grid.Row="2">FAIL</TextBox>
<TextBox Grid.Row="3">TOTAL</TextBox>
<TextBox Text="{Binding Path=IVR_S}" Grid.Row="1" Grid.Column="1" />
<TextBox Text="{Binding Path=PAYMENT_S}" Grid.Row="1" Grid.Column="2" />
<TextBox Text="{Binding Path=CALL_S}" Grid.Row="1" Grid.Column="3" />
<TextBox Text="{Binding Path=IVR_F}" Grid.Row="2" Grid.Column="1" />
<TextBox Text="{Binding Path=PAYMENT_F}" Grid.Row="2" Grid.Column="2" />
<TextBox Text="{Binding Path=CALL_F}" Grid.Row="2" Grid.Column="3" />
<TextBox Text="{Binding Path=IVR-T}" Grid.Row="3" Grid.Column="1" />
<TextBox Text="{Binding Path=PAYMENT-T}" Grid.Row="3" Grid.Column="2" />
<TextBox Text="{Binding Path=CALL-T}" Grid.Row="3" Grid.Column="3" />
</Grid>
</DockPanel>

Resources