Binding conconst value to a table - wpf

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>

Related

Silverlight : How to access control in DataGrid RowDetailTemplate

I have below code and I wanted to get the "btnUpdate" button control in the RowDetailsTemplate and set the visibility in code behind. How can I do that? Any advice is appreciated and thanks in advance.
<Grid x:Name="LayoutRoot" Background="White">
<Grid HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top" >
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<Grid HorizontalAlignment="Left" Name="grid2" VerticalAlignment="Top" Grid.RowSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500" />
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="111*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="Refresh" Click="btnRefresh_Click" Grid.Column="1" Height="23" HorizontalAlignment="Right" Name="btnRefresh" VerticalAlignment="Top" Width="80"/>
<Button Content="Add" Click="btnAdd_Click" Grid.Column="2" Height="23" HorizontalAlignment="Right" Name="btnInsert" VerticalAlignment="Top" Width="80" />
<sdk:Label Height="28" HorizontalAlignment="Left" Name="Title" VerticalAlignment="Top" Content="Title" HorizontalContentAlignment="Left" FontSize="20" FontWeight="Bold" Width="Auto"/>
</Grid>
<data:DataGrid x:Name="OverviewDataGrid" Grid.Row="1" AutoGenerateColumns="False" RowEditEnded="OverviewDataGrid_RowEditEnded" SelectionChanged="OverviewDataGrid_SelectionChanged">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Code" Binding="{Binding code, TargetNullValue=(enter code)}" IsReadOnly="True"></data:DataGridTextColumn>
<data:DataGridTextColumn Header="Description" Binding="{Binding description}" IsReadOnly="True"></data:DataGridTextColumn>
<data:DataGridTemplateColumn Header="Delete">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btnDelete" Content="Delete" Click="btnDelete_Click"></Button>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn >
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btnCollapse" Grid.Column="0" Grid.Row="0" Content="+" Click="btnCollapse_Click" HorizontalAlignment="Center" Width="20" VerticalAlignment="Center" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
<data:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Border BorderThickness="0" Background="BlanchedAlmond" Padding="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.17*"/>
<ColumnDefinition Width="0.30*"/>
<ColumnDefinition Width="0.17*"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock FontSize="12" Text="Code : " VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" Margin="1"/>
<TextBlock FontSize="12" FontWeight="Bold" Foreground="MidnightBlue" Text="{Binding code}" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="0" Margin="1" Grid.ColumnSpan="3"/>
<TextBlock FontSize="12" Text="Description: " VerticalAlignment="Center" Grid.Column="0" Grid.Row="1" Margin="1"/>
<TextBox FontSize="12" Text="{Binding description, Mode=TwoWay}" Width="350" TextWrapping="NoWrap" HorizontalAlignment="Left"
AcceptsReturn="True" Grid.Column="1" Grid.Row="1" Margin="1" Grid.ColumnSpan="3"/>
<Button x:Name="btnUpdate1" Content="Update" Click="btnUpdate_Click" HorizontalAlignment="Left" Grid.Column="1" Grid.Row="4" Margin="1"/>
</Grid>
</Border>
</DataTemplate>
</data:DataGrid.RowDetailsTemplate>
</data:DataGrid>
</Grid>
</Grid>
Follow below steps to get the control in RowDetailsTemplate.
Add loadingRowDetails event {LoadingRowDetails="yourDataGrid_LoadingRowDetails"} into datagrid in xaml.
Add below code at xaml class
private void yourDataGrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
{
Button btn = (e.DetailsElement as FrameworkElement).FindName("btnUpdate") as Button;
if (ok.Equals(false))
btn.Visibility = System.Windows.Visibility.Collapsed;
}

How to use only 1 grid layout for both header and detail with itemscontrol?

Now, when i want to create a table with a header and detail i have to define a columns 2 times for each row. the first row is header and the second row i used itemscontrol to binding data.
below is my sample code.
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource WidthColumn}" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding ListTitle}"/>
<TextBlock Grid.Column="1" Text="{Binding ListDetailTitle}" />
<TextBlock Grid.Column="2" Text="{Binding ListValueTitle}" />
</Grid>
<StackPanel Grid.Row="1">
<ItemsControl ItemsSource ="{Binding Samples}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type parameters:SampleParameters}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource WidthColumn}" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Position}"/>
<TextBox Grid.Column="1" DataContext="{Binding Name}" Text="{Binding Value}"/>
<Button Grid.Column="2" Name="Button"/>
</Grid>
</DataTemplate>
</ItemsControl.Resources>
</ItemsControl>
</StackPanel>
</Grid>
Can it use only 1 time grid layout? or there is another solution to do with?

TextBlock TextWrapping not wrapping inside StackPanel

I have a StackPanel, but the following line :
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Notes}" TextWrapping="Wrap" />
is not Wrapping the Text.
<StackPanel Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Id, StringFormat='#\{0\}'}" />
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Name}" />
</DockPanel>
<TextBlock Grid.Row="0" Grid.Column="4" FontWeight="Bold" Text="{Binding Path=Time, StringFormat={}{0:HH:mm}}" />
<Image
Grid.Row="0"
Grid.Column="6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="{Binding Path=Image, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Notes}" TextWrapping="Wrap" />
<Image
Grid.Row="1"
Grid.Column="4"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Source="{Binding Path=Picture, Mode=OneWay, Converter={StaticResource PictureConverter}}" />
</Grid>
</StackPanel>
The StackPanel Orientation is set to 'Vertical' but the TextBlock is not inheriting it.
Where am I going wrong?
Your problem is using the StackPanel that allows its children to fill in all the available space - the StackPanel stretches accordingly to the size of its content. Try removing the StackPanel and keep just the Grid - this way you will limit the size of its children to the available space used by the Grid.
If that isn't enough in the layout you've built, try setting a MaxWidth on the TextBox that needs wrapping.
Now the source of your problem was also the fact that your TextBox was inserted in the first Column of the Grid that had an infinite size (Width="Auto"). Thus, setting the Grid.Column="7" to the TextBox did the trick you wanted (wrapping text). Here's the revised code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0">
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Id, StringFormat='#\{0\}'}" />
<TextBlock FontWeight="Bold" Padding="0,0,5,0" Text="{Binding Path=Name}" />
</DockPanel>
<TextBlock Grid.Row="0" Grid.Column="4" FontWeight="Bold" Text="{Binding Path=Time, StringFormat={}{0:HH:mm}}" />
<Image
Grid.Row="0"
Grid.Column="6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Source="{Binding Path=Image, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="7" Text="{Binding Notes}" TextWrapping="Wrap" />
<Image
Grid.Row="1"
Grid.Column="4"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Source="{Binding Path=Picture, Mode=OneWay, Converter={StaticResource PictureConverter}}" />
</Grid>

Have to replicate this layout in XAML, what controls would you use?

I'm just beginning on figuring out what works best for layout/data display in XAML (WPF), and don't have the intuition yet of what controls, etc work well in certain situations.
Nothing needs to be sorted or filtered, columns and rows are static
Would using a datagrid or some combination of stackpanels/listboxes be best?
I see the "tricky" parts as being adding the "skew adjusted" sub-heading and the separating lines between some of the columns, what would be some suggestions to add these?
I would actually use the standard Grid (not the DataGrid). It seems ankward at the beginning but after you learn how to use it, you're gonna use it everywhere! :)
Here is an example to display your data (its not complete but you see the point):
<Grid x:Name="grdData" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" FontSize="14" Padding="10">Annualized Statistics</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1">1Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2">2Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3">3Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="4">4Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="5">5Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="6">1st Half</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="7">2nd Half</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="8">Incept</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Return</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1">(4.81)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2">(2.25)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="3">1.01</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="4">4.30</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="5">(0.61)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="6">(18.75)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="7">5.06</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="8">(7.48)</TextBlock>
<Rectangle Grid.Column="5" Grid.Row="1" Grid.RowSpan="5" Fill="Black" Width="1" HorizontalAlignment="Right" />
<Rectangle Grid.Column="7" Grid.Row="1" Grid.RowSpan="5" Fill="Black" Width="1" HorizontalAlignment="Right" />
</Grid>

Scroll Viewer not visible in wpf DataGrid

I have a datagrid in a grid but the scrollviewer is not visibile even though I made it auto.
Below in my code. I can't figure out where's the problem.
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Doctor Name" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Doctor Address" Grid.Row="1" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Entry Note" Grid.Row="2" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Join Date" Grid.Row="3" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Default Discount" Grid.Row="4" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Discount Valid Till" Grid.Row="5" Grid.Column="0" Margin="5,5,0,0"/>
<TextBlock Text="Employee Name" Grid.Row="6" Grid.Column="0" Margin="5,5,0,0"/>
<Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Report Type" Grid.Row="0" Grid.Column="0" Margin="5,5,0,0"/>
<ComboBox Grid.Row="0" Grid.Column="1" Name="cmbReportType" Text="{Binding CurrentEntity.ReportType}"/>
<Button Grid.Row="0" Grid.Column="2" Name="btnAddDetail" Content="Add Details" Command="{Binding AddDetailsCommand}"/>
</Grid>
<TextBox Grid.Row="0" Grid.Column="1" Margin="5,5,0,0" Width="190" Name="txtDocName" Text="{Binding CurrentEntity.RefName}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="75" Name="txtDocAddress" Text="{Binding CurrentEntity.RefAddress}"/>
<TextBox Grid.Row="2" Grid.Column="1" Margin="5,5,0,0" Width="190" Height="100" Name="txtEntryNote" Text="{Binding CurrentEntity.EntryNotes}"/>
<Custom:DatePicker Grid.Row="3" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpJoinDate" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DateStarted}" SelectedDateFormat="Short"/>
<TextBox Grid.Row="4" Grid.Column="1" Height="25" Width="75" Name="txtDefaultDiscount" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Top" Text="{Binding CurrentEntity.DefaultDiscount}"/>
<Custom:DatePicker Grid.Row="5" Grid.Column="1" Margin="5,3,0,0" Width="125" Name="dtpValidTill" Height="24" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{Binding CurrentEntity.DefaultDiscountValidTill}" SelectedDateFormat="Short"/>
<ComboBox Grid.Row="6" Grid.Column="1" Margin="5,3,0,0" Width="190" Height="30" Name="cmbEmployeeName" ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedIndex="{Binding SelecteIndex}">
</ComboBox>
<Custom:DataGrid Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding XYZ}" AutoGenerateColumns="False" Name="grdTestDept">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding dep_id}" Width="40" Header="ID"/>
<Custom:DataGridTextColumn Binding="{Binding dep_name}" Width="125" Header="Name"/>
<Custom:DataGridTextColumn Binding="{Binding default_data}" Width="100" Header="Default Data"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
<Grid Grid.Row="0" Grid.Column="1" Grid.RowSpan="9">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="43"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="150"></ColumnDefinition>
<ColumnDefinition Width="Auto" MinWidth="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="34*" ></RowDefinition>
<RowDefinition Height="337.88*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Name: " Grid.Row="0" Grid.Column="0" Margin="5,4,0,0" />
<cc:ValueEnabledCombo Grid.Column="1" x:Name="cmbfilEmployeeName" Width="150" Height="30" Margin="5,4,0,0" VerticalAlignment="Top" SelectedIndex="0"
ItemsSource="{Binding Employees}" DisplayMemberPath="FullName" SelectedValuePath="EmployeeId" cc:ValueEnabledCombo.SelectionChanged="{Binding SelectionChangedCommand}">
</cc:ValueEnabledCombo>
<Button Grid.Column="2" Name="btnReport" Width="50" Content="Report" Height="28" Margin="5,4,0,0" Command="{Binding ReportCommand}" VerticalAlignment="Top" />
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
<Custom:DataGrid ItemsSource="{Binding DoctorList}" AutoGenerateColumns="False" Name="grdDoctor" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding RefName}" Width="Auto" Header="Doctor Name"/>
<Custom:DataGridTextColumn Binding="{Binding EmployeeFullName}" Width="Auto" Header="Employee Name"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</Grid>
</Grid>
</Grid>
Kent Boogaart posted the answer here:
how can I enable scrollbars on the WPF Datagrid?
Put the DataGrid in a Grid, DockPanel, ContentControl or directly in the Window. A vertically-oriented StackPanel will give its children whatever vertical space they ask for - even if that means it is rendered out of view.
My note: It's probably best not to set the max height and width. Leave those alone and let WPF take care of the resizing for you.

Resources