silverlight printing using davidpoll.com collection printer - silverlight

I am working in a Silverlight 4 application. I have a datagrid that I would like to print. I am trying to use davidpoll printing functionality
Currently, I am printing just the datagrid header, but no items are being printed
<SLaB:CollectionPrinter x:Name="printer" ItemsSource="{Binding CurrentSearchView}" >
<SLaB:CollectionPrinter.BodyTemplate>
<DataTemplate>
<sdk:DataGrid x:Name="dgResults" VerticalAlignment="Stretch" SelectionMode="Single" HorizontalAlignment="Stretch" AutoGenerateColumns="False" ItemsSource="{Binding CurrentSearchView}" IsReadOnly="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" Margin="10" FontSize="12" FontFamily="Segoe UI" >
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Binding="{Binding PeopleId}" Header="People ID" Width="150"/>
<sdk:DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="*" MinWidth="80"/>
<sdk:DataGridTemplateColumn Header="FQ" Width="80">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel x:Name="spFq" Background="{Binding FqBackground}" Margin="2">
<Image Source="{Binding FqImagePath}" Margin="4" Height="24" Width="24"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="LQ" Width="80" CellStyle="{StaticResource BrowseQualityCellStyle}">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel x:Name="spLq" Orientation="Horizontal" Background="{Binding LqBackground}" Margin="2" >
<myControls:PlayButtonControl x:Name="playControl" Margin="4" Height="24" Width="24" />
<Image Source="{Binding LqImagePath}" Margin="4" Height="16" Width="16"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn Binding="{Binding Format}" Header="Format" Width="Auto"/>
<sdk:DataGridTextColumn Binding="{Binding Duration}" Header="Duration" Width="Auto"/>
<sdk:DataGridTextColumn Binding="{Binding Attachment}" Header="Attachment" Width="Auto"/>
<sdk:DataGridTextColumn Binding="{Binding Restore}" Header="Restore" Width="Auto"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</DataTemplate>
</SLaB:CollectionPrinter.BodyTemplate>
</SLaB:CollectionPrinter>
And here is the button command
<Button Command="{Binding PrintCommand, ElementName=printer}">Print</Button>
Note that both, the collectionprinter and datagrid are referencing the same property CurrentSearchView, which is a PagedCollectionView. I think that my problem lies there, maybe I am not able to used this kind of collection (i also try with an observable collection and found the same results), or my bindings are wrong (having both controls referencing the same property, doesn't seem right)
Any help will be greatly appreciated.
Thanks

I have found the problem. I needed to set the binding of the datagrid to "CurrentItems"
<sdk:DataGrid x:Name="dgResults" VerticalAlignment="Stretch" SelectionMode="Single" HorizontalAlignment="Stretch" AutoGenerateColumns="False" ItemsSource="{Binding CurrentItems}" IsReadOnly="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" Margin="10" FontSize="12" FontFamily="Segoe UI" >

Related

WPF DataGrid Master/Detail: How to show Master property within Detail that's within a different ItemSource

I have an object hierarchy of this: Orders have Allocations. My DataGrid has an ItemSource of Orders which then shows some details of each order in each grid row. Upon clicking on a grid row, a details pane comes up with additional details including a list of Allocations for each order. What I need to do is to somehow reference back to the Master record and pull a bit of detail (which would end up repeating) for each allocation. If I try to RelativeSource back to the DataGrid, I cannot refer to the property since that source is a whole collection and I need to get the value off of the item of that collection.
Below is a simplified version of the XAML I'm using. Basically, I need to bind to QuantityTypeDescription that's in the master record from each Allocation item in the child (Order) record.
<DataGrid ItemsSource="{Binding Orders}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Trade" Binding="{Binding TransactionTypeDescription}" Width="*"/>
<DataGridTextColumn Header="Adjustment" Binding="{Binding QuantityTypeDescription}" Width="Auto"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--Order Summary-->
<StackPanel Orientation="Vertical">
<StackPanel Background="DarkSlateGray" Orientation="Vertical">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding TransactionTypeDescription}" FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="White"/>
</StackPanel>
<TextBlock Name="Name" Text="{Binding SecurityName}" HorizontalAlignment="Center" FontWeight="Bold" Foreground="White" Background="DarkSlateGray"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ItemsControl ItemsSource="{Binding Allocations}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
NOTE: Here I need to get back up one level to get QuantityTypeDescription
<!--<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid, AncestorLevel=1}, Path=QuantityTypeDescription}" Margin="5,0,0,0"/>-->
<TextBlock Text="{Binding Amount}" Margin="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
Use ElementName Binding to refer to your main DataGrid's SelectedItem
<DataGrid Name="MainDataGrid" ItemsSource="{Binding Orders}" AutoGenerateColumns="False" IsReadOnly="True" HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns>
<DataGridTextColumn Header="Trade" Binding="{Binding TransactionTypeDescription}" Width="*"/>
<DataGridTextColumn Header="Adjustment" Binding="{Binding QuantityTypeDescription}" Width="Auto"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<!--Order Summary-->
<StackPanel Orientation="Vertical">
<StackPanel Background="DarkSlateGray" Orientation="Vertical">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding TransactionTypeDescription}" FontWeight="Bold" Margin="5,0,0,0" FontSize="14" Foreground="White"/>
</StackPanel>
<TextBlock Name="Name" Text="{Binding SecurityName}" HorizontalAlignment="Center" FontWeight="Bold" Foreground="White" Background="DarkSlateGray"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<ItemsControl ItemsSource="{Binding Allocations}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ElementName=MainDataGrid,Path=SelectedItem.QuantityTypeDescription}" Margin="5,0,0,0"/>
<TextBlock Text="{Binding Amount}" Margin="5,0,0,0"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>

Showing Hiding a control inside datagrid in silverlight with MVVM

I have a datagrid like below
**strong text**
<sdk:DataGrid AutoGenerateColumns="False" Height="Auto" MaxHeight="500"
HorizontalAlignment="Left" Margin="5" Name="_EmployeeGrid"
ItemsSource="{Binding Path= Employees,Mode=TwoWay}"
HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Visibility="Visible"
VerticalAlignment="Top" Width="Auto">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Employee ID" IsReadOnly="True" Binding="{Binding Path=EmpID}"/>
<sdk:DataGridTemplateColumn Header="Name" SortMemberPath="EmpID">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton VerticalAlignment="Center" NavigateUri="{Binding Path=EmpID,
Converter={StaticResource NavigatePropertyUriConverter}, ConverterParameter=EmpView}"
Content= "{Binding Path=EmpID}" >
</HyperlinkButton>
<!--<HyperlinkButton NavigateUri= "{ Binding Converter={StaticResource navigateConv}, ConverterParameter=/Property/IssuesView?}" VerticalAlignment="Center"
Content="{Binding Path=PropertyId}"
HorizontalAlignment="Right" Margin="5"/>-->
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<!--<sdk:DataGridTextColumn Header="Property #" IsReadOnly="True" Binding="{Binding Path=PropertyId}"/>-->
<sdk:DataGridTextColumn Header="Address" IsReadOnly="True" Binding="{Binding Path=Address}"/>
<sdk:DataGridTextColumn Header="Category" IsReadOnly="True" Binding="{Binding Path=CategoryName}"/>
<sdk:DataGridTextColumn Header="Phone" IsReadOnly="True" Binding="{Binding Path=UnitId}" Visibility="Collapsed"/>
<!--<sdk:DataGridTextColumn Header="Notes" Binding="{Binding Comments}" IsReadOnly="False" />-->
<sdk:DataGridTemplateColumn x:Name="Notes1" Header="Notes">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock MaxWidth="200" TextAlignment="Left" TextWrapping= "Wrap" Text="{Binding Path=Comments, Mode=OneWay}" Width="200" />
<HyperlinkButton Name="btnEllipsis" Visibility="{Binding EllipsisVisibility,Source={StaticResource ViewModel}}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="15" Content="..." ToolTipService.ToolTip="Click For More" Command="{Binding NotesCommand,Source={StaticResource ViewModel}}" CommandParameter="{Binding}" >
</HyperlinkButton>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid>
and associated property in viewmodel as below
strong text
string _ellipsisVisibility;
public string EllipsisVisibility
{
get { return _ellipsisVisibility; }
set
{
if (_ellipsisVisibility != value)
{
_ellipsisVisibility = value;
RaisePropertyChanged("EllipsisVisibility");
}
}
}
and setting it to
EllipsisVisibility="Collapsed";
and
EllipsisVisibility="Visible";
There are two questions
1. It is not working to show or hide column
2. Need to show the hyperlink button in few rows and or hide in few rows based on some condition like Rowdatabound event in asp.net.
How to do can anyone please help???
(1) DataGrid column visibility is, unfortunately, not a dependency property. This means it can't engage in databinding. Some work-arounds to this involve subclassing the column type you're interested in.
(2) To show/hide a particular control, based on the data for that row, I would use a converter. Or create a new property on that entity type to directly bind to.

WPF dataGrid super Header for multiple columns

I want to do Header for multiple columns in WPF DataGrid. I tried with Header template but it will display Header for one column.
Below XAML I have tried:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>Column 1</TextBlock>
<TextBlock>xyz</TextBlock>
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
<DataGridTextColumn Header="Header" />
</DataGrid.Columns>
</DataGrid>
I am also attaching the My expected result screen shoot:
<Grid Width="Auto">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<toolkit:DataGrid x:Name="problemsList"
MinHeight="205"
MaxHeight="205"
Margin="3"
VerticalAlignment="Top"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="True"
CanUserResizeRows="False"
ColumnHeaderStyle="{StaticResource GridColumnHeaderStyle}"
HorizontalScrollBarVisibility="Visible"
ItemsSource="{Binding FisapCorrections}"
MouseLeftButtonUp="problemsList_MouseLeftButtonUp"
SelectionMode="Single"
Sorting="problemsList_Sorting"
VerticalScrollBarVisibility="Auto">
<toolkit:DataGrid.Columns>
<toolkit:DataGridTemplateColumn MinWidth="50"
CellTemplate="{StaticResource RowSelected}"
Header="Select" />
<toolkit:DataGridTextColumn MinWidth="88"
Binding="{Binding StudentName}"
Header="Student Name"
IsReadOnly="True" />
<toolkit:DataGridTextColumn x:Name="dgtcSSN"
MinWidth="50"
Binding="{Binding SSN}"
Header="SSN"
IsReadOnly="True" />
<toolkit:DataGridTextColumn x:Name="dgtcStuNum"
MinWidth="50"
Binding="{Binding StuNum}"
Header="StuNum"
IsReadOnly="True" />
<toolkit:DataGridTextColumn MinWidth="80"
Binding="{Binding Campus}"
Header="Campus"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="50"
MinWidth="50"
Binding="{Binding BadModel,
Converter={StaticResource ToEmptyStringConverter}}"
Header="BadModel"
HeaderTemplate="{StaticResource DepModelHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="72"
MinWidth="72"
Binding="{Binding BadPellEnrollStatus,
Converter={StaticResource ToEmptyStringConverter}}"
CanUserReorder="False"
Header="BadPellEnrollStatus"
HeaderTemplate="{StaticResource EnrollStatusHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="75"
MinWidth="75"
Binding="{Binding DupePell,
Converter={StaticResource ToEmptyStringConverter}}"
Header="DupePell"
HeaderTemplate="{StaticResource DupStudentPellHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="80"
MinWidth="80"
Binding="{Binding BadTransactionId,
Converter={StaticResource ToEmptyStringConverter}}"
Header="BadTransactionId"
HeaderTemplate="{StaticResource InvTransactionIDHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="40"
MinWidth="40"
Binding="{Binding HasNoISIR,
Converter={StaticResource ToEmptyStringConverter}}"
Header="HasNoISIR"
HeaderTemplate="{StaticResource NoISIRHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="75"
MinWidth="75"
Binding="{Binding GradWithSEOG,
Converter={StaticResource ToEmptyStringConverter}}"
Header="GradWithSEOG"
HeaderTemplate="{StaticResource NotEligxSEOGHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="100"
MinWidth="100"
Binding="{Binding GradIsDependent,
Converter={StaticResource ToEmptyStringConverter}}"
Header="GradIsDependent"
HeaderTemplate="{StaticResource GradWithDepModelHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="60"
MinWidth="60"
Binding="{Binding NoClasses,
Converter={StaticResource ToEmptyStringConverter}}"
Header="NoClasses"
HeaderTemplate="{StaticResource NoClassesHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTextColumn Width="65"
MinWidth="65"
Binding="{Binding Ineligible}"
Header="Ineligible"
HeaderTemplate="{StaticResource SchoolStatusHeaderTemplate}"
IsReadOnly="True" />
<toolkit:DataGridTemplateColumn IsReadOnly="True">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="Main Header Text" Grid.columnSpan="3" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="Text 1" grid.Column="0" grid.Row="1"/>
<TextBlock Text="Text 2" grid.Column="1" grid.Row="1"/>
<TextBlock Text="Text 3" grid.Column="2" grid.Row="1"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
<toolkit:DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Missing from FISAP Summary Part II Section F"
TextWrapping="Wrap"
Width="200"/>
</DataTemplate>
</toolkit:DataGridTemplateColumn.HeaderTemplate>
</toolkit:DataGridTemplateColumn>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
<CmcControls:WaitingControl x:Name="waitingControlOnGrid"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
I want to add the Expected result in the Last of the Grid
Try This;->
You Just need to use 2 Rows and 3 Columns if you want the way your ScreenShot depicts.
In First Row define your TextBlock with Grid.ColumnsSpan="3" which will take space for 3 Columns and In Second Row define each TextBlock in each Different Column:
<DataGrid ItemsSource="{Binding FisapCorrections,RelativeSource={RelativeSource AncestorType=Window},UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}">
<DataGrid.Columns>
<DataGridTemplateColumn Width="200">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="70"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Main Header Text" Height="100" Grid.ColumnSpan="3" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="Text 1" Height="100" Grid.Column="0" Grid.Row="1"/>
<TextBlock Text="Text 2" Grid.Column="1" Grid.Row="1"/>
<TextBlock Text="Text 3" Grid.Column="2" Grid.Row="1"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

WPF Toolkit Datagrid Copying Grid

I'm using the datagrid from the WPF Toolkit for 3.5.
I have a need to TextWrap one of my columns in this grid so have embedded a TextBlock in this column.
The issue I have now is that when I copy the grids content into excel (Ctrl A, Ctrl C) this column is blank.
Any help on resolving this would be much appreciated. Below is my XAML for the grid.
<tk:DataGrid Name="dgDataGrid" Margin="3" AutoGenerateColumns="False" HeadersVisibility="All"
ClipboardCopyMode="IncludeHeader" SnapsToDevicePixels="True"
CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"
SelectionMode="Extended" SelectionUnit="Cell">
<tk:DataGrid.Columns>
<tk:DataGridTextColumn Binding="{Binding ID}" Header="Message ID" Visibility="Hidden" FontWeight="Black" />
<tk:DataGridTextColumn Binding="{Binding UserInitials}" Header="User" Width="Auto" />
<tk:DataGridTextColumn Binding="{Binding EntryDate}" Header="Time Stamp" Width="Auto" />
<tk:DataGridTemplateColumn Header="Message" Width="*">
<tk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding Message}" TextWrapping="Wrap"/>
</DataTemplate>
</tk:DataGridTemplateColumn.CellTemplate>
</tk:DataGridTemplateColumn>
</tk:DataGrid.Columns>
</tk:DataGrid>
Set the ClipboardContentBinding property on the DataGridTemplateColumn.

Why this code doesn't work? :(

<dg:DataGrid Name="gridList" AutoGenerateColumns="False"
ItemsSource="{Binding ItemsInTable}" HeadersVisibility="Column" >
<dg:DataGrid.RowDetailsTemplate >
<DataTemplate x:Name="ItemDetails" >
<Border HorizontalAlignment="Stretch" CornerRadius="5" Background="Azure" >
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<ComboBox Name="cboxDepartment" SelectedItem="{Binding Department}" DisplayMemberPath="Desc" ItemsSource="{Binding DeptosInTable}" ></ComboBox>
</StacPanel>
</Border>
</DataTemplate>
</dg:DataGrid.RowDetailsTemplate>
<dg:DataGridTextColumn Header="DEPARTMENT" Binding="{Binding Department}" Width="180" IsReadOnly="True">
Department is a property in a class. DeptosInTable is a ObservableCollection with 2 properties: ID and Desc.
One error you have made (I'm not sure if it's the only one):
</StacPanel>
Should be:
</StackPanel>

Resources