Skip to content

Instantly share code, notes, and snippets.

@biac
biac / MyCheckBox.cs
Last active December 16, 2015 21:29
バインドでも IsThreeState が有効になる ChackBox をでっち上げた f(^^; override できなかったので new した。ので、何かあっても知らんので、よろ (汗; プロパティの型を bool? にすると実行時にブチ落ちるのはなぜなんだぜ? orz
public class MyCheckBox : CheckBox
{
public new object IsChecked
{
get { return GetValue(IsCheckedProperty); }
set { SetValue(IsCheckedProperty, value); }
}
public static new readonly DependencyProperty IsCheckedProperty =
DependencyProperty.Register("IsChecked", typeof(object), typeof(MyCheckBox),
new PropertyMetadata(null, new PropertyChangedCallback(OnIsCheckedChanged)));
@biac
biac / MainPage.xaml
Last active December 16, 2015 02:08
ListBox で選択されている Item の Index をデータにバインドしてみる。 [2013/4/12] データが int のときは右詰め、それ以外の時は左詰めにしてみた。 バリュー・コンバータについては、この記事参照(ステマw > http://www.atmarkit.co.jp/ait/articles/1304/11/news027.html
<!-- ページ・リソースにバリュー・コンバータとデータ・テンプレートを追加 -->
<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">My Application</x:String>
<local:ObjectTypeToTextAlignmentConverter x:Key="ObjectTypeToTextAlignmentConverter" />
<DataTemplate x:Key="MyListboxItemTemplate">
<Grid HorizontalAlignment="Stretch" Width="150" Margin="0,0,20,0">
@biac
biac / gist:4634046
Created January 25, 2013 12:24
WP8 で PictureAlbum の中の画像を取り出してみるテスト
using Microsoft.Xna.Framework.Media;
using System;
namespace PhoneApp1
{
public class PhotoAlbums
{
public static Picture GetFirstPhoto() {
MediaLibrary mediaLib = new MediaLibrary();
foreach (var album in mediaLib.RootPictureAlbum.Albums)
@biac
biac / calendar.cs
Created December 9, 2012 02:21
カレンダーを表示するコード
var firstDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
int dayOfWeek= (int)firstDate.DayOfWeek; //日曜=0 … 土曜=6
int lastDay = firstDate.AddMonths(1).AddDays(-1).Day;
for (int day = 1; day <= lastDay; day++)
{
int index = (day - 1) + dayOfWeek; // 左上のマスを0番として、左から右へ数えていった番号
int x = index % 7; // column(横方向)位置
int y = index / 7; // row(縦方向)位置
var color = Windows.UI.Colors.White;
@biac
biac / calendar.xaml
Created December 9, 2012 02:20
カレンダー用のグリッドを描く
<Grid x:Name="CalendarGrid" Grid.Row="1" Margin="120,20,40,20" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
@biac
biac / WindowsPhoneRuntimeComponent1.cpp
Created December 8, 2012 08:57
MultiByteToWideChar を呼び出す Windows Phone ランタイム コンポーネント
#include "pch.h"
#include "WindowsPhoneRuntimeComponent1.h"
#define CP_SJIS 932
using namespace WindowsPhoneRuntimeComponent1;
using namespace Platform;
Platform::String^ WindowsPhoneRuntimeComponent::MultiByteToWideCharWP8(const Platform::Array<byte>^ buff)
{
@biac
biac / TextDecoder.cs
Created December 8, 2012 08:54
Win8 Metro で MultiByteToWideChar を使う
public class TextDecoder
{
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
static extern int MultiByteToWideChar(
uint CodePage,
uint dwFlags,
[MarshalAs(UnmanagedType.LPArray)] byte[] lpMultiByteStr,
int cbMultiByte,
[Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpWideCharStr,
int cchWideChar);
@biac
biac / MainPage.xaml.cs
Created December 8, 2012 08:58
WP8 の C# から Windows Phone ランタイム コンポーネントを使う
private async void ReadFile()
{
// バイト配列に読み込んでから、MultiByteToWideChar()を通す
const string FileUrl = "ms-appx:///TextFile1.txt";
var storage = await StorageFile.GetFileFromApplicationUriAsync(new Uri(FileUrl));
using (var stream = await storage.OpenReadAsync())
{
byte[] buff = new byte[stream.Size];
await stream.AsStreamForRead().ReadAsync(buff, 0, buff.Length);
@biac
biac / CustomGridView.cs
Created December 3, 2012 01:23
GridView 中の ScrollViewer の余白と水平スクロール位置を指定できる、拡張コントロール
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace BluewaterSoft.DevTools.Win8Common.Control
{
public class CustomGridView : GridView
{
private ScrollViewer _sv;
private ItemsPresenter _ip;
@biac
biac / MainPage.xaml
Created November 27, 2012 03:22
GridViewのスクロール位置を復元するには
<!-- GridView を ScrollViewer に埋め込んでやる。GridView のサイズは、その中身だけで決まるようになる。 -->
<ScrollViewer x:Name="ScrollViewer1" Grid.Row="1"
HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Disabled" >
<GridView x:Name="GridView1" Margin="120,0,0,0" SizeChanged="GridView1_SizeChanged"
SelectedIndex="-1"
ItemsSource="{Binding Source={StaticResource definedColorsSource}}"
ItemTemplate="{StaticResource ColorInfoDataTemplate150x150}" />
</ScrollViewer>