< April 2009 | May 2009 | June 2009 >

May 15, 2009

カンマ区切りされた数字を配列として取り出したりとか。

別にカンマ区切りじゃなくていいんやけど。

class Test
{
    static void Main (string [] args)
    {
        var s = "e0,106,aa,12";
        var regex = new System.Text.RegularExpressions.Regex ("\\b(\\d+)\\b");
        var matches = regex.Matches (s);
        var numbers = matches
            .OfType<System.Text.RegularExpressions.Match> ()
            .Select (match => Convert.ToInt32 (match.Groups [1].Value))
            .ToArray ();
        foreach (var number in numbers)
            Console.WriteLine ("{0}:{1}", number, number.GetType ());
    }
}

Visual Studio 2008 で、XAML デザイナを開くと異常終了する

Visual Studio 2008 で XAML ファイルを開くと VS 自体が異常終了するようになってしまった。以下イベントログ。

ソース: .NET Runtime
種類: エラー
イベント ID: 1023
説明:
.NET Runtime version 2.0.50727.3082 - 致命的な実行エンジン エラーが発生しました (7A2E1132) (0)

VS2008 crashes with "Fatal Execution Engine Error"」に、以下の投稿があった。

Thanks to Paul I found a very strange workaround (I verified it a few times)

  • open the solution
  • unload the project (context menu)
  • edit the csproj (context menu), don't make any changes
  • reload the project (contect menu)

If I do that before I start the debugger VS will not crash.

つまり

  1. ソリューションを開く
  2. コンテキストメニューより [プロジェクトのアンロード]
  3. コンテキストメニューより [編集 WpfApplication1.csproj] して、何も編集を行わない。
  4. コンテキストメニューより [プロジェクトの再読み込み]

嘘みたいだが、これで本当に解決。

May 12, 2009

System.Windows.Input.InputMethod

System.Windows.Input.InputMethod の添付プロパティの挙動がよくわかんない。

<Window x:Class="WpfSample.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="テキストボックスで IME の ON/OFF を指定する"
        SizeToContent="Height" Width="300">
    <Window.Resources>
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5"/>
        </Style>
        <Style TargetType="Label">
            <Setter Property="VerticalContentAlignment" Value="Center"/>
        </Style>
    </Window.Resources>    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Content="IME ON:" Grid.Row="0"/>
        <TextBox InputMethod.PreferredImeState="On" Grid.Column="1" Grid.Row="0" Text="On のはず"/>
        <Label Content="IME OFF:" Grid.Row="1"/>
        <TextBox InputMethod.PreferredImeState="Off" Grid.Column="1" Grid.Row="1" Text="Off のはず"/>
    </Grid>
</Window>

とりあえず、これで意図したとおりにうごくっぽい。