windows setup: implement awesomely styled list view

This commit is contained in:
Hylke Bons 2012-03-09 02:51:43 +00:00
parent b22068d669
commit 6aa2d26d97
2 changed files with 45 additions and 20 deletions

View file

@ -16,18 +16,20 @@
using System; using System;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO;
using System.Media;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Forms.Integration; using System.Windows.Forms.Integration;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Data;
using System.Media;
using WPF = System.Windows.Controls; using WPF = System.Windows.Controls;
namespace SparkleShare { namespace SparkleShare {
@ -233,29 +235,52 @@ namespace SparkleShare {
SelectionMode = SelectionMode.Single SelectionMode = SelectionMode.Single
}; };
GridView grid_view = new GridView (); GridView grid_view = new GridView () {
AllowsColumnReorder = false
grid_view.Columns.Add ( };
new GridViewColumn {
DisplayMemberBinding = new Binding ("Text") grid_view.Columns.Add (new GridViewColumn ());
}
); string xaml =
"<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"" +
// TODO: " xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" +
// - Disable column headers " <Grid>" +
// - Add plugin images " <StackPanel Orientation=\"Horizontal\">" +
// - Nicer markup: <b>Name</b>\n<small>Description</small> " <Image Margin=\"5,0,0,0\" Source=\"{Binding Image}\" Height=\"24\" Width=\"24\"/>" +
" <StackPanel>" +
" <TextBlock Padding=\"10,4,0,0\" FontWeight=\"Bold\" Text=\"{Binding Name}\">" +
" </TextBlock>" +
" <TextBlock Padding=\"10,0,0,4\" Opacity=\"0.5\" Text=\"{Binding Description}\">" +
" </TextBlock>" +
" </StackPanel>" +
" </StackPanel>" +
" </Grid>" +
"</DataTemplate>";
grid_view.Columns [0].CellTemplate = (DataTemplate) XamlReader.Parse (xaml);
Style header_style = new Style(typeof (GridViewColumnHeader));
header_style.Setters.Add (new Setter (GridViewColumnHeader.VisibilityProperty, Visibility.Collapsed));
grid_view.ColumnHeaderContainerStyle = header_style;
foreach (SparklePlugin plugin in Controller.Plugins) { foreach (SparklePlugin plugin in Controller.Plugins) {
BitmapFrame image = BitmapFrame.Create (
new Uri (plugin.ImagePath)
);
list_view.Items.Add ( list_view.Items.Add (
new { new {
Text = plugin.Name + "\n" + plugin.Description Name = plugin.Name,
}); Description = plugin.Description,
Image = image
}
);
} }
list_view.View = grid_view; list_view.View = grid_view;
list_view.SelectedIndex = Controller.SelectedPluginIndex; list_view.SelectedIndex = Controller.SelectedPluginIndex;
TextBlock address_label = new TextBlock () { TextBlock address_label = new TextBlock () {
Text = "Address:", Text = "Address:",
FontWeight = FontWeights.Bold FontWeight = FontWeights.Bold

View file

@ -37,7 +37,7 @@ namespace SparkleShare {
Stream image_stream = assembly.GetManifestResourceStream ("SparkleShare.Pixmaps." + name + ".png"); Stream image_stream = assembly.GetManifestResourceStream ("SparkleShare.Pixmaps." + name + ".png");
return BitmapFrame.Create (image_stream); return BitmapFrame.Create (image_stream);
} }
public static Bitmap GetBitmap (string name) public static Bitmap GetBitmap (string name)
{ {