Skip to content

Instantly share code, notes, and snippets.

@biac
biac / Downloader1.cs
Created Nov 27, 2012
WP8 で WebRequest を使うとき、GetResponse() を await したいよね!
View Downloader1.cs
private static Task<WebResponse> GetResponseAsync(WebRequest request)
{
return Task.Run<WebResponse>(() =>
{
AutoResetEvent autoResetEvent = new AutoResetEvent(false);
// BeginGetResponse で autoResetEvent を発火させる
IAsyncResult asyncResult = request.BeginGetResponse(r => autoResetEvent.Set(), null);
// autoResetEvent.Set() の発火を待つ。すなわちここでブロックする
@biac
biac / 参加者.cs
Created Jun 11, 2012
Kujian - 参加者.cs (Create 時に並びをランダムにする)
View 参加者.cs
public static IList<参加者> Create()
{
// …前略
}).ToList();
int count = list.Count;
var rnd = new Random();
for (int i = 0; i < count; i++)
{
int src = rnd.Next(0, count);
@biac
biac / SplitPage.xaml.cs
Created Jun 11, 2012
Kujian - SplitPage.xaml.cs (NEXT ボタン)
View SplitPage.xaml.cs
private void NextButton_Click_1(object sender, RoutedEventArgs e)
{
itemListView.Background = backButton.Background;
var selected = itemListView.SelectedItem as Kujian.Data.SampleDataItem;
var dataGroup = itemListView.DataContext as Kujian.Data.SampleDataGroup;
dataGroup.Items.Remove(selected);
}
@biac
biac / SplitPage.xaml.cs
Created Jun 11, 2012
Kujian - SplitPage.xaml.cs (STOP ボタン)
View SplitPage.xaml.cs
private async void Button_Click_2(object sender, RoutedEventArgs e)
{
_isContinue = false;
while (!_isBreaking)
await Task.Delay(50);
itemListView.Background = new SolidColorBrush(Colors.DarkGray);
int remain = 5000;
@biac
biac / SplitPage.xaml.cs
Created Jun 11, 2012
Kujian - SplitPage.xaml.cs (START ボタン)
View SplitPage.xaml.cs
private void Button_Click_1(object sender, RoutedEventArgs e)
{
itemListView.Background = backButton.Background;
Rotate();
}
private bool _isContinue;
private bool _isBreaking;
@biac
biac / SampleDataSource.cs
Created Jun 11, 2012
Kujian - DataModel/SampleDataSource (変更後)
View SampleDataSource.cs
public SampleDataSource()
{
String ITEM_CONTENT = String.Format("Item Content: {0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}",
"Curabitur class …中略…");
var group1 = new SampleDataGroup("Group-1",
"くじ庵", //"Group Title: 1",
"Group Subtitle: 1",
"Assets/DarkGray.png",
"Group Description: Lorem ipsum …中略… ante a ante");
@biac
biac / SampleDataSource.cs
Created Jun 11, 2012
Kujian - DataModel/SampleDataSource (変更前)
View SampleDataSource.cs
public SampleDataSource()
{
String ITEM_CONTENT = String.Format("Item Content: {0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}\n\n{0}",
"Curabitur class …中略…");
var group1 = new SampleDataGroup("Group-1",
"Group Title: 1",
"Group Subtitle: 1",
"Assets/DarkGray.png",
"Group Description: Lorem ipsum …中略… ante a ante");
@biac
biac / gist:2909056
Created Jun 11, 2012
Kujian - ボタンを追加
View gist:2909056
<Grid Grid.Column="1" x:Name="ControlGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button x:Name="StartButton" Content="START" Click="Button_Click_1" />
<Button x:Name="StopButton" Content="STOP" Click="Button_Click_2" Grid.Column="1" />
<Button x:Name="NextButton" Content="Next" Click="NextButton_Click_1" Grid.Column="2" />
@biac
biac / gist:2909045
Created Jun 11, 2012
Kujian - データテンプレートを持ってきて修正
View gist:2909045
<DataTemplate x:Key="DataTemplate1">
<Grid Height="Auto" Margin="6" Opacity="{Binding DataContext.Content, RelativeSource={RelativeSource Mode=Self}}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="110" Height="110"
VerticalAlignment="Center" >
<Image Source="{Binding Image}" Stretch="UniformToFill"/>
</Border>
@biac
biac / 参加者.cs
Created Jun 11, 2012
Kujian - 参加者データ
View 参加者.cs
public class 参加者
{
private const string OriginalData =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<ol>
<li><span><img alt=""5zj"" class=""icon"" height=""18"" src=""http://a0.twimg.com/profile_images/64048378/20081110-235006-41046300_normal.gif"" width=""18"" /><a href=""/users/46103"" class="""">5zj</a> : <em>いたって真面目なイベントです。</em></span></li>
…中略(約40人分)…
</ol>";