忍者ブログ
2009/12/12作成
.NET
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

[.NET].NETでサポートされたプログラム言語のソースコード変換サイト




#サイト変換
1developer FussionC#⇒VB
2VB⇒C#
PR
[WPF]DataGridの指定セルにフォーカスする
[WPF]ViewModelを介してDataGridにバインディングするにボタンを一つ配置し、以下のようなクリックハンドラとメソッドを作る。

private void button1_Click(object sender, RoutedEventArgs e)
{
    int rowIndex = 0;
    int colIndex = 1;
    // 行、列の番号を指定してDataGridCellを取得する
    DataGridCell cell = GetDataGridCell(dataGrid1, rowIndex, colIndex);
    // データグリッドセルにフォーカスする
    FocusManager.SetFocusedElement(this, cell);
}

public DataGridCell GetDataGridCell(DataGrid dataGrid, int rowIndex, int columnIndex)
{
    if (dataGrid.Items == null || dataGrid.Items.IsEmpty)
    {
        return null;
    }
    DataGridRow row = GetDataGridRow(dataGrid, rowIndex);
    if (row != null)
    {
        DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
        DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
        if (cell == null)
        {
            // Visual Treeが構築されていない場合もあるため更新
            dataGrid.UpdateLayout();
            dataGrid.ScrollIntoView(row, dataGrid.Columns[columnIndex]);
            cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
        }
        return cell;
    }
    return null;
}

public DataGridRow GetDataGridRow(DataGrid dataGrid, int index)
{
    if (dataGrid.Items == null || dataGrid.Items.IsEmpty)
    {
        return null;
    }
    DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
    if (row == null)
    {
        // Visual Treeが構築されていない場合もあるため更新
        dataGrid.UpdateLayout();
        dataGrid.ScrollIntoView(dataGrid.Items[index]);
        row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
    }
    return row;
}

public static T GetVisualChild<T>(Visual parent) where T : Visual
{
    T result = default(T);
    int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
    for (int i = 0; i < childrenCount; i++)
    {
        Visual child = (Visual)VisualTreeHelper.GetChild(parent, i);
        result = child as T;
        if (result == null)
        {
            result = GetVisualChild<T>(child);
        }
        if (result != null)
        {
            break;
        }
    }
    return result;
}


[WPF] KeyDownをプログラムから呼び出す
○WPFプロジェクト内から呼び出す場合

Dim key As Key = Key.Insert
Dim target As UIElement = Keyboard.FocusedElement
Dim routedEvent As RoutedEvent = Keyboard.KeyDownEvent
Dim e As KeyEventArgs = New KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            PresentationSource.FromVisual(target),
                            0,
                            key)
e.RoutedEvent = routedEvent
Grid1.RaiseEvent(e)



○単体テストプロジェクト内から呼び出す場合

Dim params As HwndSourceParameters = New HwndSourceParameters()
Dim source As HwndSource = New HwndSource(params)
Dim k As Key = Key.A
Dim e As KeyEventArgs = New KeyEventArgs(Keyboard.PrimaryDevice, source, 0, k)
e.RoutedEvent = routedEvent
Grid1.RaiseEvent(e)


ClickOnce

ClickOnce


「Webアプリのメリットは、バージョンアップはサーバーサイドのみでよい。」
「それに比べ、クラサバではバージョンアップのたび再インストールが必要。」
と比較することで、Webアプリのメリットを示したことがある。

が、ClickOnceは、クラサバのデメリットをほとんど無視できる機能だと思った。
つまり再インストールをワンクリックでできるようにする。
インストーラを配信するサイトを自動生成したり、
アプリケーション起動時に、バージョンアップを促すこともできるみたい。

参考文献⇒7. アプリケーションの配置
.NETのアセンブリについて

.NETが出る以前


.NETが出る以前は、COMを使っていて、
アプリケーションで使用するdllファイルは、
レジストリにパスが書かれていた。

.NETが出てから


.NETになってから、アセンブリ(dllやexe)の管理機能を強化された。
これによりアセンブリを検索が可能になり、レジストリが必要なくなった。

検索タイミングは、アプリケーションの起動時で、
検索の処理は、以下の順序で行う。
1.GAC(グローバルアセンブリキャッシュ)
2.アプリケーション構成ファイルに記載のある場所

2にはさらにいくつかの検索項目があるけど、
そこはmsdnを参照。

わかったこと


.NETではインストールはXCOPYでいいってこと。

xcopy /I /S <配置元パス> <配置先パス>


参考文献⇒6. アプリケーションの実行までの流れ
Powered by [PR]
/ Design by sky hine / PR:忍者ブログ