Cannot display image on gridview data binding from local package - c#

I have a gridview with data bindings that contain titles and book covers. Cover the book is in the local package with the name of the path: "files/kurikulum 2006/[The name of the folder selected by the user on the previous page]/cover".I have trouble displaying the cover of the book so that the book cover does not appear and the error message appears as below:
But for the title can be displayed on the gridview.
XAML:
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Grouped Items"
Margin="0,0,10,0"
HorizontalAlignment="Center"
ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick" BorderThickness="0">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="315" Width="200" Margin="5,10,0,0" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" Margin="10,10,10,10" Height="230" Width="180" Source="{Binding Image}" AutomationProperties.Name="{Binding Name}" />
<Grid Grid.Row="1" Margin="0,0,10,10" HorizontalAlignment="Left" Height="50" >
<ScrollViewer Margin="10,10,5,5" VerticalAlignment="Top" HorizontalAlignment="Left" Height="40" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<TextBlock Margin="0,0,10,10" Text="{Binding Name}" Foreground="Black" FontSize="25" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Segoe UI Black" FontWeight="SemiBold" TextAlignment="Center" TextWrapping="Wrap" Height="40" Width="auto"/>
</ScrollViewer>
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Code:
ObservableCollection<Book> datasource = new ObservableCollection<Book>();
StorageFolder _folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
_folder = await _folder.GetFolderAsync("files");
_folder = await _folder.GetFolderAsync(direktori.Direktori);
_folder = await _folder.GetFolderAsync(direktori.Name);
_folder = await _folder.GetFolderAsync("cover");
IReadOnlyList<StorageFile> _files = await _folder.GetFilesAsync(); //which returns List<StorageFile>
foreach (StorageFile file in _files)
{
Book buku = new Book();
buku.Name = file.DisplayName.ToString();
StorageFile thumbFile;
thumbFile = await _folder.GetFileAsync(file.DisplayName.ToString() + ".jpg");
BitmapImage bi = new BitmapImage();
bi.SetSource(await thumbFile.OpenAsync(FileAccessMode.Read));
buku.Image = bi;
datasource.Add(buku);
}
itemGridView.ItemsSource = datasource;
Book class:
public class Book
{
public string Name { get; set; }
public string Direktori { get; set; }
public ImageSource Image { get; set; }
}
How to handle it?
Note:
direktori.Direktori = kurikulum 2006 (or the other folder)
direktori.Name = The name of the folder selected by the user on the previous page

Related

My Print PDF Doesn't Show the Binded Data of the Original Window - C# MVVM

I am trying to print my window (Print Preview) using MVVM architecture. So far I was able to get the controls of the window into the print. But it doesn't show the data bindings.
This is my PrintPreview.xaml code
<ScrollViewer VerticalScrollBarVisibility="Auto">
<!--Main Grid-->
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2.5*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height ="1.5*"/>
<RowDefinition Height ="1.7*"/>
<RowDefinition Height ="5*" MinHeight="200"/>
<RowDefinition Height ="7*" MinHeight="200"/>
<RowDefinition Height ="6*" MinHeight="100"/>
<RowDefinition Height ="2*"/>
</Grid.RowDefinitions>
<Grid Grid.RowSpan="2" Grid.ColumnSpan="3" Background="#9dc6a7"/>
<!--Patient Id block-->
<StackPanel Grid.ColumnSpan="2" Style="{StaticResource StackpanelStyle}">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Patient ID :
</Label>
<Label FontSize="16" Foreground="White" Margin="5,0,0,0" Content="{Binding Path=PatientID}"/>
</StackPanel>
<!--Date block-->
<StackPanel Grid.ColumnSpan="3" Style="{StaticResource StackpanelStyle}" HorizontalAlignment="Right">
<Label FontSize="16" FontWeight="Bold" Foreground="White">
Date :
</Label>
<Label Name="date_time" FontSize="16" Foreground="White" Margin="5,0" Content="{Binding Path=CurrentDate}"/>
</StackPanel>
<!--Title block-->
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="Bold" TextDecorations="Underline" Foreground="White">
Patient Registration Information
</TextBlock>
<!--Sub grid 1-->
<Grid Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Stretch" Margin="25,10,25,10">
<!--User's image View and name-->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical">
<Ellipse Width="150" Height="150">
<Ellipse.Fill>
<ImageBrush x:Name="ImageViewer2" ImageSource="{Binding Path=PatientImageSource}"/>
</Ellipse.Fill>
</Ellipse>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="0,10">
<Label Style="{StaticResource LabelStyles}" Margin="0">Patient Name :</Label>
<TextBlock x:Name="ViewName" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientName}"/>
</StackPanel>
</StackPanel>
</Grid>
<!--Sub grid 2-->
<GroupBox Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="25,-35,25,0">
<GroupBox.Header>
<TextBlock Style="{StaticResource TextBlockStyleControl}">Patient Personal Information</TextBlock>
</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="500*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5*"/>
<RowDefinition Height="3*" MaxHeight="80"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}" >Address :</Label>
<TextBlock x:Name="ViewANum" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientAddress.Number}"/>
<TextBlock x:Name="ViewAStrt" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientAddress.Street}"/>
<TextBlock x:Name="ViewACity" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientAddress.City}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,10">
<Label Style="{StaticResource PreviewLabelStyles}">Gender :</Label>
<TextBlock x:Name="ViewGender" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientGender}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Date of Birth :</Label>
<TextBlock x:Name="ViewDob" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientDateOfBirth}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Age :</Label>
<TextBlock x:Name="ViewAge" Style="{StaticResource TextBlockStyle}" Text="{Binding Path = PatientAge}"/>
</StackPanel>
</Grid>
</GroupBox>
<!--Sub grid 3-->
<GroupBox Grid.Row="4" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="25,-25,25,0">
<GroupBox.Header>
<TextBlock Style="{StaticResource TextBlockStyleControl}">Patient Medical Information</TextBlock>
</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="500*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical" Margin="10,5">
<Label Style="{StaticResource PreviewLabelStyles}">Department :</Label>
<TextBlock x:Name="ViewDepartment" Style="{StaticResource TextBlockStyle}" Text="{Binding Path=PatientDepartment}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="50,5,10,0">
<Label Style="{StaticResource PreviewLabelStyles}">Ward :</Label>
<TextBlock x:Name="ViewWard" Style="{StaticResource TextBlockStyle}" Text="{Binding Path=PatientWard}"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Vertical" Margin="10,5,10,10">
<Label Style="{StaticResource PreviewLabelStyles}">Doctor in Charge :</Label>
<TextBlock x:Name="ViewDoc" Style="{StaticResource TextBlockStyle}" Text="{Binding Path=PatientDotorcInCharge}"/>
</StackPanel>
</Grid>
</GroupBox>
<Button Grid.Row="5" Grid.Column="2" Style="{StaticResource ButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="20,7,26,0" Content="Print Content" Command="{Binding Path=PrintCommand}"/>
</Grid>
</ScrollViewer>
This is my PrintPreview ViewModel code,
class PrintPreviewViewModel
{
#region Data Members
private IWindowService m_windowService;
#endregion
#region Constructors
public PrintPreviewViewModel(PatientRecordDetailsModel patient)
{
string id = patient.PatientId;
PatientID = id.PadRight(6).Substring(0, 6);
PatientName = patient.PatientName;
PatientAddress = patient.PatientAddress;
PatientGender = patient.PatientGender;
PatientDateOfBirth = patient.PatientDateOfBirth.ToShortDateString();
PatientAge = patient.PatientAge;
PatientImageSource = patient.PatientImageSource;
PatientDepartment = patient.PatientDepartment;
PatientWard = patient.PatientWard;
PatientDotorcInCharge = patient.PatientDoctorInCharge;
m_windowService = new WindowService();
}
#endregion
#region Properties
public string PatientID { get; set; }
public string PatientName { get; set; }
public PatientAddress PatientAddress { get; set; }
public string PatientGender { get; set; }
public string PatientDateOfBirth { get; set; }
public int PatientAge { get; set; }
public ImageSource PatientImageSource { get; set; }
public string PatientDepartment { get; set; }
public string PatientWard { get; set; }
public string PatientDotorcInCharge { get; set; }
#endregion
#region <PrintPreview> Members
public string CurrentDate => m_windowService.GetCurrentDate();
#endregion
#region Properties : Commands
public ICommand PrintCommand
{
get => new PatientRecordDetailsCommands(param => OnPrintCommandExecute(), param => OnPrintCommandCanExecute());
}
#endregion
#region Handlers : Commands
private void OnPrintCommandExecute()
{
m_windowService.PrintWindow();
}
private bool OnPrintCommandCanExecute()
{
return true;
}
#endregion
}
}
As you can see I am opening the printPreview Window from another window through a service class. The patient object is being send through that. Also the implementation of print button command is also defined in the same service class. I used this approach to reduce the MVVM violations.
This is my Service class
class WindowService : IWindowService
{
public void CreateWindow(PatientRecordDetailsModel patient)
{
PrintPreview printPreview = new PrintPreview();
printPreview.DataContext = new PrintPreviewViewModel(patient);
printPreview.Show();
}
public string GetCurrentDate()
{
DateTime dateTime = DateTime.Now;
string date = dateTime.ToString("d");
string time = dateTime.ToString("T");
string Date_Time = date + " " + time;
return Date_Time;
}
public void PrintWindow()
{
PrintPreview printPreview = new PrintPreview();
PrintDialog printDlg = new PrintDialog();
PrintQueue ReceiptPrinter = new LocalPrintServer().GetPrintQueue("Microsoft Print To PDF");
PrintCapabilities PC = ReceiptPrinter.GetPrintCapabilities();
printDlg.PrintQueue = ReceiptPrinter;
printPreview.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
Size PreGridSize = printPreview.DesiredSize;
double Scale = Math.Min(PC.PageImageableArea.ExtentWidth / PreGridSize.Width, PC.PageImageableArea.ExtentHeight / PreGridSize.Height);
printPreview.LayoutTransform = new System.Windows.Media.ScaleTransform(Scale, Scale);
Size PaperSize = new Size(PC.PageImageableArea.ExtentWidth, Math.Min(PC.PageImageableArea.ExtentHeight, PreGridSize.Height));
printPreview.Measure(PaperSize);
Point ptGrid = new Point(PC.PageImageableArea.OriginWidth, PC.PageImageableArea.OriginHeight);
printPreview.Arrange(new Rect(ptGrid, PaperSize));
Application.Current.Dispatcher.BeginInvoke(
new Action(delegate () { printDlg.PrintVisual(printPreview.MainGrid, "PrintPreview"); }),
DispatcherPriority.Send);
}
}
I tried assigning the patient object to the datacontext inside the PrintWindow(), but it returns a null object.
This is the original printPreview Window
This is how the print looks like
So I guess there should be a proper way of doing this.
Your problem is that you're not assigning the DataContext inside your PrintWindow function.
let's take a look
public void PrintWindow()
{
here we create a new printpreview
PrintPreview printPreview = new PrintPreview();
PrintDialog printDlg = new PrintDialog();
PrintQueue ReceiptPrinter = new LocalPrintServer().GetPrintQueue("Microsoft Print To PDF");
PrintCapabilities PC = ReceiptPrinter.GetPrintCapabilities();
printDlg.PrintQueue = ReceiptPrinter;
printPreview.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
Size PreGridSize = printPreview.DesiredSize;
double Scale = Math.Min(PC.PageImageableArea.ExtentWidth / PreGridSize.Width, PC.PageImageableArea.ExtentHeight / PreGridSize.Height);
printPreview.LayoutTransform = new System.Windows.Media.ScaleTransform(Scale, Scale);
Size PaperSize = new Size(PC.PageImageableArea.ExtentWidth, Math.Min(PC.PageImageableArea.ExtentHeight, PreGridSize.Height));
printPreview.Measure(PaperSize);
Point ptGrid = new Point(PC.PageImageableArea.OriginWidth, PC.PageImageableArea.OriginHeight);
printPreview.Arrange(new Rect(ptGrid, PaperSize));
Application.Current.Dispatcher.BeginInvoke(
new Action(delegate () { printDlg.PrintVisual(printPreview.MainGrid, "PrintPreview"); }),
DispatcherPriority.Send);
}
as you can see you don't assign the datacontext to it. Indeed the createiwndow function in which you do assign the data context is not called at all.
you can see here the print command calls the PrintWindow function instead of createwindow.
#region Properties : Commands
public ICommand PrintCommand
{
get => new PatientRecordDetailsCommands(param => OnPrintCommandExecute(), param => OnPrintCommandCanExecute());
}
#endregion
#region Handlers : Commands
private void OnPrintCommandExecute()
{
m_windowService.PrintWindow();
}
private bool OnPrintCommandCanExecute()
{
return true;
}
#endregion

Converting FrameworkElement to Jpeg in UWP

At the past, I can convert and save an usercontrol to an JPEG image with this code:
private string CreateBitmapImage(FrameworkElement usefulData, string name) // Tekli görev kartını masaüstünde oluşturmak için, resim yaratma fonksiyonu.
{
try
{
string fullFileName = string.Empty;
Size size = new Size(642, 416);
usefulData.Measure(size);
usefulData.Arrange(new Rect(size));
var rtb = new RenderTargetBitmap((int)usefulData.ActualWidth, (int)usefulData.ActualHeight, 96, 96, PixelFormats.Pbgra32);
rtb.Render(usefulData);
var encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = "Görev kartını nereye kaydetmek istersiniz ?";
dlg.FileName = name; // Default file name
dlg.DefaultExt = ".jpg"; // Default file extension
dlg.Filter = "Resim Dosyası (.jpg)|*.jpg"; // Filter files by extension
dlg.OverwritePrompt = true;
var result = dlg.ShowDialog();
if (result == true && dlg.CheckPathExists == true)
{
fullFileName = System.IO.Path.Combine(dlg.FileName);
using (var filestream = new FileStream(fullFileName, FileMode.Create))
{
encoder.Save(filestream);
}
}
return fullFileName;
}
catch
{
MessageBox.Show("Tek görev kartını yaratırken bir hata oluştu.Lütfen yeniden deneyin.", "Hata", MessageBoxButton.OK, MessageBoxImage.Error);
return "";
}
}
Now, I'm converting my WPF project to UWP. However, I cannot find how I convert and save an usercontrol to an Jpeg image in UWP. Can you help me please ?
Thanks.
Update: My UserControl in UWP. As I explained at bottom, I got an exception if I try render the user control:
<UserControl
x:Class="AYOS_IDPrinter_UWP.TaskCard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AYOS_IDPrinter_UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="416"
d:DesignWidth="642" HorizontalAlignment="Center" VerticalAlignment="Center" RequestedTheme="Default">
<UserControl.Resources>
<SolidColorBrush x:Key="AuSupportColor" Color="#FFE5C97C"/>
</UserControl.Resources>
<Border x:Name="OutSketch" BorderThickness="2" BorderBrush="{StaticResource AuSupportColor}">
<Grid x:Name="MainGrid" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border x:Name="NeedleArea" BorderThickness="0,0,0,2" Background="{StaticResource AUColor}" BorderBrush="{StaticResource AuSupportColor}">
<TextBlock x:Name="Label" TextWrapping="Wrap" Text="İğne Alanı / Needle Area" Foreground="White" TextAlignment="Center" Margin="0" VerticalAlignment="Center" FontFamily="Noto Sans" FontWeight="Normal"/>
</Border>
<Grid x:Name="Values" HorizontalAlignment="Stretch" Margin="10,10,10,10" VerticalAlignment="Stretch" Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="Header" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="128"/>
<ColumnDefinition/>
<ColumnDefinition Width="128"/>
</Grid.ColumnDefinitions>
<Image x:Name="Logo1" Source="Images/AULogo.png" Margin="0" Grid.RowSpan="4" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100"/>
<Image x:Name="Logo2" Source="Images/AnkudemLogo.png" Margin="0" Grid.RowSpan="4" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100"/>
<TextBlock x:Name="Header_1" Grid.Column="1" Margin="0" TextWrapping="Wrap" Text="AYÖS" FontSize="28" TextAlignment="Center" FontWeight="Bold" Foreground="#FF284985" FontFamily="Noto Sans"/>
<TextBlock x:Name="Header_2" Grid.Column="1" Margin="0" TextWrapping="Wrap" Text="SINAV GÖREV KARTI" FontSize="24" TextAlignment="Center" Grid.Row="1" Foreground="#FF284985" FontFamily="Noto Sans"/>
<TextBlock x:Name="Header_3" Grid.Column="1" Margin="0" TextWrapping="Wrap" Text="EXAMINATION TASK CARD" FontSize="24" TextAlignment="Center" Grid.Row="2" Foreground="#FF284985" FontFamily="Noto Sans"/>
<TextBlock x:Name="DateText" Grid.Column="1" Margin="0" TextWrapping="Wrap" FontSize="22" TextAlignment="Center" Grid.Row="3" Foreground="#FF284985" Text="28 Mayıs 2016 – May 28, 2016" FontFamily="Noto Sans"/>
</Grid>
<Grid x:Name="Data" Grid.Row="1" Margin="0,18,0,-17">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="NameText" Margin="0,10,0,0" TextWrapping="Wrap" FontSize="32" TextAlignment="Center" Foreground="Red" Text="BERK BABADOĞAN" FontWeight="Bold" FontFamily="Noto Sans"/>
<TextBlock x:Name="TaskText" Margin="0,0,0,10" TextWrapping="Wrap" Text="Salon Başkanı" FontSize="28" TextAlignment="Center" Foreground="Black" Grid.Row="1" FontFamily="Noto Sans"/>
</Grid>
<Grid x:Name="Specs" Margin="10" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="SpecsH_1" Margin="0,0,5,0" TextWrapping="Wrap" Text="Sınav Yeri / Exam Area: " FontSize="20" Foreground="#FF343434" FontStyle="Italic" FontWeight="Bold" VerticalAlignment="Center" FontFamily="Noto Sans"/>
<TextBlock x:Name="SpecsH_2" Margin="0,0,5,0" TextWrapping="Wrap" Text="Salon Adı / Hall Name:" FontSize="20" Foreground="#FF343434" Grid.Row="1" FontStyle="Italic" FontWeight="Bold" VerticalAlignment="Center" FontFamily="Noto Sans"/>
<TextBlock x:Name="SpecsH_3" Margin="0,0,5,0" TextWrapping="Wrap" Text="Salon No / Hall Number:" FontSize="20" Foreground="#FF343434" Grid.Row="2" FontStyle="Italic" FontWeight="Bold" VerticalAlignment="Center" FontFamily="Noto Sans"/>
<TextBlock x:Name="AreaText" Margin="5,0,0,0" TextWrapping="Wrap" Text="İstanbul" FontSize="20" Foreground="#FF343434" FontStyle="Italic" Grid.Column="1" VerticalAlignment="Center" FontFamily="Noto Sans"/>
<TextBlock x:Name="HallNameText" Margin="5,0,0,0" TextWrapping="Wrap" Text="A Blok 3. Kat Derslik 316" FontSize="20" Foreground="#FF343434" Grid.Row="1" FontStyle="Italic" Grid.Column="1" VerticalAlignment="Center" FontFamily="Noto Sans"/>
<TextBlock x:Name="HallNoText" Margin="5,0,0,0" TextWrapping="Wrap" Text="340111" FontSize="20" Foreground="#FF343434" Grid.Row="2" FontStyle="Italic" Grid.Column="1" VerticalAlignment="Center" FontFamily="Noto Sans"/>
</Grid>
</Grid>
</Grid>
</Border>
It is the code how I create an instance from my user control:
var item = new TaskCard(Name_TextBox.Text.ToUpper() + " " + Surname_TextBox.Text.ToUpper(), Task_TextBox.Text, ExamArea_TextBox.Text, HallName_TextBox.Text,HallNumber_TextBox.Text,DateConverter.Get(Date_Picker.Date.ToString())); // Creating card.
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(item); // Gives error here.
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
For converting, UWP app also has RenderTargetBitmap class for capturing a UIElement as an image source. For file saving, you could reference this turtorial. In UWP app we have FileSavePicker which is similar to SaveFileDialog. For example, a completed demo as follows:
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(elementToRender, 642,416);
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
var savePicker = new FileSavePicker();
savePicker.DefaultFileExtension = ".png";
savePicker.FileTypeChoices.Add(".png", new List<string> { ".png" });
savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
savePicker.SuggestedFileName = "snapshot.png";
// Prompt the user to select a file
var saveFile = await savePicker.PickSaveFileAsync();
// Verify the user selected a file
if (saveFile == null)
return;
// Encode the image to the selected file on disk
using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
DisplayInformation.GetForCurrentView().LogicalDpi,
DisplayInformation.GetForCurrentView().LogicalDpi,
pixelBuffer.ToArray());
await encoder.FlushAsync();
}
More details you could reference the official XAML render to bitmap sample.
Update:
Also add the XAML code section which use a UserControl for testing. What pass to the RenderAsync method should be the name of the Element you want to render.
<local:MyUserControl
x:Name="elementToRender"
Width="100"
Height="150" />
I did some researches why I can't render a TargetBitmap from code. I found a reason at this link:
You cannot save visual element which in code (offscreen) to image.
So, I foluna a new way to render my code based user control. I created my user control via code like this:
//Initializing task card.
var item = new TaskCard(Name_TextBox.Text.ToUpper() + " " + Surname_TextBox.Text.ToUpper(), Task_TextBox.Text, ExamArea_TextBox.Text, HallName_TextBox.Text, HallNumber_TextBox.Text, DateConverter.Get(Date_Picker.Date.ToString())); // Creating card.
After this, I added a custom popup-like element with this:
<Border x:Name="RingBorder" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="{ThemeResource SystemControlBackgroundBaseHighRevealBorderBrush}" BorderThickness="2,2,2,2" RequestedTheme="Default" Visibility="Collapsed" >
<Grid x:Name="InnerGrid_Ring" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Default" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid x:Name="WaiterRing_SecondRow" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="LoadValue_Ring" Text="Lütfen bekleyin..." TextWrapping="Wrap" FontWeight="Normal" Margin="10,0,10,0" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1" Style="{StaticResource TitleTextBlockStyle}" />
<ProgressRing x:Name="Waiter_Ring" HorizontalAlignment="Center" Margin="10,10,10,10" VerticalAlignment="Center" Foreground="{StaticResource AndroidGreen}" IsActive="True" Width="40" Height="40"/>
</Grid>
<Grid x:Name="CardViewerGrid_Ring" HorizontalAlignment="Center" Height="416" Margin="0,0,0,0" VerticalAlignment="Center" Width="642"/>
</Grid>
</Border>
Lastly, I'm rendering the user control like this:
//Converting UIelement to Rendered Bitmap
CardViewerGrid_Ring.Children.Add(item); // Adding card to canvas.
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(CardViewerGrid_Ring); // Render canvas.
var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
And, voila :)

Displays the image on the flipview, when the image on the gridview is clicked

I have json as below:
I want to display the data in the gallery on the gridview, then if the user clicks the image on the gridview, it will show a picture with a larger size on the flipview according to the selected image. I'm having trouble, that is when the image on the gridview is selected, it always shows up the image on the flipview for the first index (not in accordance with the picture chosen by the user).
XAML:
<callisto:CustomDialog x:FieldModifier="public" x:Name="ArticleDetail"
Grid.Row="0" Grid.RowSpan="2" Title=""
Background="White" BackButtonVisibility="Collapsed" BorderBrush="White" >
<ScrollViewer Margin="0,0,5,5" Background="{x:Null}" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Disabled">
<StackPanel Height="auto">
<ProgressRing x:Name="articleDetailLoading" HorizontalAlignment="Center" VerticalAlignment="Center" Height="50" Width="50" />
<StackPanel x:Name="articleDetailBox" Margin="0,0,10,10" Height="auto">
<Grid x:Name="articleDetailGrid" BorderBrush="#FF990000" BorderThickness="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="articleIdDetail" Grid.Row="0" Text="{Binding ID}" Visibility="Collapsed"/>
<AppBarButton x:Name="closeArticleBtn" Icon="Clear" HorizontalAlignment="Right" Foreground="Black" Click="closeArticleBtn_Click"/>
<ScrollViewer x:Name="articleTitleScroll" Grid.Row="1" Margin="10,0,0,0" Width="650" Height="50" VerticalAlignment="Top" HorizontalAlignment="Left" VerticalScrollBarVisibility="Auto" Background="{x:Null}" HorizontalScrollMode="Disabled">
<TextBlock x:Name="articleTitleDetail" Margin="0,0,15,15" FontSize="18" FontFamily="Segoe UI Black" FontWeight="SemiBold" TextWrapping="Wrap" Height="auto" TextAlignment="Center"/>
</ScrollViewer>
<TextBlock x:Name="articleDateDetail" Grid.Row="3" Margin="10,15,10,0" FontSize="15" FontFamily="Segoe UI Black" FontWeight="SemiLight" TextWrapping="Wrap" Height="auto" TextAlignment="Center"/>
<GridView x:Name="articleImageGridView" Grid.Row="5" Margin="10,25,10,0" Height="110" AutomationProperties.AutomationId="ItemDetailScrollViewer" DataContext="{Binding SelectedItem, ElementName=itemListView}"
ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Auto" IsItemClickEnabled="True"
ScrollViewer.ZoomMode="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemClick="articleImageGridView_ItemClick">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="90" Width="120" Margin="5,0,0,0" Background="{x:Null}" BorderBrush="#FF646464" BorderThickness="0.5">
<Border x:Name="coverBox" Grid.Row="0" Margin="0,0,0,0" Width="120" Height="90" VerticalAlignment="Top" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="0.5">
<Border.Background>
<ImageBrush Stretch="UniformToFill" ImageSource="images/IP-placeholder.png"/>
</Border.Background>
<Image x:Name="cover" Source="{Binding ImageURL1}" HorizontalAlignment="Center" Stretch="Uniform" AutomationProperties.Name="{Binding Title}" ImageOpened="Image_ImageOpened" Loaded="cover_Loaded" Loading="cover_Loading"/>
</Border>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
<WebView x:Name="articleContentDetail" Grid.Row="6" Margin="10,15,10,10" Width="650" Height="150" VerticalAlignment="Top" HorizontalAlignment="Left"/>
</Grid>
</StackPanel>
<StackPanel x:Name="articleFullImageDetailBox" Margin="0,0,10,10" Height="auto" Visibility="Collapsed">
<Grid x:Name="articleFullImageDetailGrid" BorderBrush="#FF990000" BorderThickness="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<AppBarButton x:Name="closearticleFullImageBtn" Grid.Column="1" Icon="Clear" HorizontalAlignment="Right" Foreground="Black" Click="closearticleFullImageBtn_Click"/>
<TextBlock x:Name="articleFullIdDetail" Grid.Row="0" Text="{Binding ID}" Visibility="Collapsed"/>
<FlipView x:Name="articleImageFullFlipview" Grid.Row="1" Grid.RowSpan="3" Grid.Column="0" Margin="0,0,0,0" ItemsSource="{Binding gallery.Items}" SelectedItem="{Binding gallery, Mode=TwoWay}" Width="650" Height="500" VerticalAlignment="Center" HorizontalAlignment="Left" BorderBrush="Black" BorderThickness="1" Background="{x:Null}">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid x:Name="content" Margin="0,0,0,0">
<Border x:Name="coverBox" Width="600" Height="500">
<Border.Background>
<ImageBrush Stretch="Uniform" ImageSource="images/IP-placeholder.png"/>
</Border.Background>
<Image x:Name="cover" Source="{Binding ImageURLFull}" HorizontalAlignment="Center" Stretch="UniformToFill" AutomationProperties.Name="{Binding ID}" ImageOpened="Image_ImageOpened" Loaded="cover_Loaded" Loading="cover_Loading"/>
</Border>
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
</Grid>
</StackPanel>
</StackPanel>
</ScrollViewer>
</callisto:CustomDialog>
Code:
ObservableCollection<ArticleClass> articleDatasourceDetailImage = new ObservableCollection<ArticleClass>();
articleDatasourceDetailImage.Clear();
articleDetailLoading.Visibility = Visibility.Visible;
articleDetailLoading.IsActive = true;
articleDetailBox.Visibility = Visibility.Collapsed;
articleFullImageDetailBox.Visibility = Visibility.Collapsed;
ArticleDetail.IsOpen = true;
articleItemDetail = e.ClickedItem as ArticleClass;
articleIdDetail.Text = articleItemDetail.ID.ToString();
ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
if (connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
{
articleDetailLoading.IsActive = true;
try
{
string urlPath = "http://indonesia-product.com/api/v1/articles/"10.json?module=articles&page=1&token=3f63-dc43-c8d5-eb45-8cbf-b72d-9d98-800f";
//Debug.WriteLine(urlPath.ToString());
var httpClient = new HttpClient(new HttpClientHandler());
var values = new List<KeyValuePair<string, string>>
{
};
HttpResponseMessage response = await httpClient.GetAsync(urlPath);
response.EnsureSuccessStatusCode();
if (!response.IsSuccessStatusCode)
{
articleDetailLoading.IsActive = false;
RequestException();
}
string jsonText = await response.Content.ReadAsStringAsync();
JsonObject jsonObject = JsonObject.Parse(jsonText);
JsonObject jsonData = jsonObject["data"].GetObject();
JsonObject groupObject1 = jsonData.GetObject();
double id = groupObject1["id"].GetNumber();
string title = groupObject1["title"].GetString();
string date = groupObject1["publication_date"].GetString();
JsonArray jsonGallery = groupObject1["gallery"].GetArray();
foreach (JsonValue groupValue1 in jsonGallery)
{
JsonObject groupObject2 = groupValue1.GetObject();
string imageUrl = groupObject2.ContainsKey("image_url") && groupObject2["image_url"] != null ? groupObject2["image_url"].GetString() : string.Empty;
ArticleClass fileImage = new ArticleClass();
fileImage.ImageURL1 = imageUrl;
articleDatasourceDetailImage.Add(fileImage);
}
articleImageGridView.ItemsSource = articleDatasourceDetailImage;
articleDetailLoading.IsActive = false;
ArticleClass file = new ArticleClass();
file.ID = Convert.ToInt32(id);
file.Title = title;
DateTime dateConvert = Convert.ToDateTime(date);
file.Date = dateConvert.ToString("MMM d, yyyy");
articleContentDetail.NavigateToString(contentText);
articleDetailLoading.IsActive = false;
articleDetailBox.Visibility = Visibility.Visible;
articleDetailLoading.Visibility = Visibility.Collapsed;
articleDetailLoading.IsActive = false;
}
catch (HttpRequestException ex)
{
articleDetailLoading.IsActive = false;
}
}
else
{
articleDetailLoading.IsActive = false;
}
}
private async void articleImageGridView_ItemClick(object sender, ItemClickEventArgs e)
{
articleDetailLoading.Visibility = Visibility.Visible;
articleDetailLoading.IsActive = true;
articleDetailBox.Visibility = Visibility.Collapsed;
articleFullImageDetailBox.Visibility = Visibility.Collapsed;
var articleImageGridView = (GridView)sender;
articleImageFullFlipview.SelectedIndex = articleImageGridView.SelectedIndex;
articleFullImageDetailBox.Visibility = Visibility.Visible;
articleDetailLoading.Visibility = Visibility.Collapsed;
articleDetailLoading.IsActive = false;
}
How to handle it?
First, there is no need to get your data again when clicking on the item. When you load your data, set the ItemsSource of your GridView and your FlipView to be the same collection.
Second, when your item is clicked, get the SelectedIndex of the item and then set the SelectedIndex of your FlipView
private async Task LoadData()
{
// get data
var response = await httpClient.GetAsync(url);
// Convert to your objects
articleImageFullFlipview.ItemsSource = data;
articleImageGridView.ItemsSource = data;
}
private void articleImageGridView_ItemClick(object sender, ItemClickEventArgs e)
{
var gridView = (GridView)sender;
articleImageFullFlipview.SelectedIndex = gridView.SelectedIndex;
// show or hide any controls
}

c# can't display the image of a RSS feed

I'm using this RSS feed for my Windows 8 Application (c#) http://www.skysports.com/rss/0,20514,11661,00. I can display the Title and PubDate but I'm stuck on the image.
private async void LoadRSS()
{
SyndicationClient client = new SyndicationClient();
Uri feedUri = new Uri("http://www.skysports.com/rss/0,20514,11661,00.xml");
SyndicationFeed feed = await client.RetrieveFeedAsync(feedUri);
FeedData feedData = new FeedData();
foreach (SyndicationItem item in feed.Items)
{
FeedItem feedItem = new FeedItem();
feedItem.Title = item.Title.Text;
feedItem.PubDate = item.PublishedDate.DateTime;
// Handle the differences between RSS and Atom feeds.
if (feed.SourceFormat == SyndicationFormat.Atom10)
{
feedItem.Content = item.Content.Text;
feedItem.Link = new Uri("http://www.skysports.com" + item.Id);
}
else if (feed.SourceFormat == SyndicationFormat.Rss20)
{
feedItem.Content = item.Summary.Text;
feedItem.Link = item.Links[0].Uri;
}
feedData.Items.Add(feedItem);
}
ItemListView.DataContext = feedData.Items;
}
xaml code:
<GridView x:Name="ItemListView" Grid.Column="2" Grid.Row="1" ItemsSource="{Binding}" ItemClick="Sports_ItemClick_1" IsItemClickEnabled="True" SelectionMode="None" >
<GridView.ItemTemplate>
<DataTemplate>
<Grid Width="400" Height="75" Margin="0,0,50,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"></ColumnDefinition>
<ColumnDefinition Width="325"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Background="#60BF89">
<Image Source="{Binding ImagePath, Mode=OneWay}" Stretch="None" Margin="5,15,0,0" VerticalAlignment="Top" HorizontalAlignment="Center" Width="500"/>
</Border>
<StackPanel Grid.Column="1" VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Foreground="White" Text="{Binding Title}" FontSize="16" Margin="5,0,0,0" TextWrapping="Wrap" />
<TextBlock Foreground="White" Text="{Binding PubDate}" FontSize="12" Margin="5,0,0,0"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
I would like the Image in the first column. Any ideas??
you are not setting ImagePath property in the code sample you showed, considering this as a problem

Grouping GridView in Windows 8 Metro App

Can someone give me some hints how to accomplish the grouping
within a GridView for Metro Apps as shown in the Screenshot below.
This Screenshot is from the Developer Resources for Windows Metro Apps,
but unfortunately there is no description how to accomplish it.
I have the following code snippet:
Xaml:
...
<Page.Resources>
<CollectionViewSource x:Name="cvs" IsSourceGrouped="true"/>
</Page.Resources>
<Grid Background="{StaticResource DefaultBackground}">
<GridView x:Name="DefaultGridView" ItemsSource="{Binding Source={StaticResource cvs}}">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding}" Width="100" Height="100" Margin="0 0 5 0"/>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text='{Binding Key}' Foreground="Gray" Margin="5" FontSize="30" FontFamily="Segoe UI Light" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid MaximumRowsOrColumns="2" Orientation="Horizontal" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</Grid>
...
C#:
In the Code-Behind I do the following in the OnNavigateTo Method:
List<string> strList = new List<string>() {
"Red", "Red", "Red", "Red", "Red", "Red",
"Green", "Green","Green","Green","Green",
"Blue","Blue","Blue","Blue" };
var groupedList = from s in strList
group s by s into g
orderby g.Key
select g;
cvs.Source = groupedList;
No matter what I do, I am not able to group the Items in a continues list like in the
Screenshot. The Code results in separate lists grouped side by side.
I may have a solution. In my projet, I had to create a list of contacts in alphabetic order, like the People app.
I used a GridView (with this sample), a CollectionViewSource and a wrappanel I found in the WinRT XAML Toolkit (you can get with NuGet package or copy/paste the source code). It allow you to put your items in columns.
Example
ViewModel
class ContactListViewModel
{
public ContactListViewModel()
{
ContactSource = new CollectionViewSource();
Contacts = new ObservableCollection<Contact>();
Contacts.Add(new Contact("Gates","Bill"));
Contacts.Add(new Contact("Bush","Georges"));
Contacts.Add(new Contact("Obama","Barack"));
Contacts.Add(new Contact("Hollande","François"));
Contacts.Add(new Contact("Affleck","Ben"));
Contacts.Add(new Contact("Allen","Woody"));
Contacts.Add(new Contact("Hendrix","Jimi"));
Contacts.Add(new Contact("Harrison", "Georges"));
Contacts = new ObservableCollection<Contact>(Contacts.OrderBy(c => c.Name));
ContactSource.Source = GetGroupsByLetter();
ContactSource.IsSourceGrouped = true;
}
#region Contacts
public ObservableCollection<Contact> Contacts
{
get;
protected set;
}
public CollectionViewSource ContactSource
{
get;
protected set;
}
#endregion
internal List<GroupInfoList<object>> GetGroupsByLetter()
{
List<GroupInfoList<object>> groups = new List<GroupInfoList<object>>();
var query = from item in Contacts
orderby ((Contact)item).Name
group item by ((Contact)item).Name[0] into g
select new { GroupName = g.Key, Items = g };
foreach (var g in query)
{
GroupInfoList<object> info = new GroupInfoList<object>();
info.Key = g.GroupName;
foreach (var item in g.Items)
{
info.Add(item);
}
groups.Add(info);
}
return groups;
}
public class GroupInfoList<T> : List<object>
{
public object Key { get; set; }
public new IEnumerator<object> GetEnumerator()
{
return (System.Collections.Generic.IEnumerator<object>)base.GetEnumerator();
}
}
}
View
<DataTemplate x:Key="contactTemplate">
<Grid Width="225" Height="75" Background="#55FFFFFF">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="20">
<Run Text="{Binding FirstName}"/>
<Run Text="{Binding Name}"/>
</TextBlock>
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding Email}" FontSize="13" Foreground="#FFDDDDDD"/>
</Grid>
</Grid>
</DataTemplate>
<DataTemplate x:Key="letterTemplate">
<Grid Margin="5,0,0,5" Width="225">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Key}" Style="{StaticResource GroupHeaderTextStyle}" VerticalAlignment="Center"/>
<Rectangle Grid.Row="1" Fill="#BBEEEEEE" Height="1" Margin="0,7,0,0"/>
</Grid>
</DataTemplate>
</Page.Resources>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" Style="{StaticResource BackButtonStyle}" Opacity="0"/>
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="Manager" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
<GridView Grid.Row="1"
ItemsSource="{Binding Path=ContactSource.View}"
SelectionMode="Multiple"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
Padding="116,10,40,46"
ItemTemplate="{StaticResource contactTemplate}">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<local:WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle HeaderTemplate="{StaticResource letterTemplate}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
</Grid>
http://code.msdn.microsoft.com/windowsapps/GroupedGridView-77c59e8e
It can't be done using the default grid view styles.
You may have to use one none-grouped item list and add special items with different item template ...
Sorry
I would add the headers as items to the gridview, and use a TemplateSelector to display the elements the right way...

Categories