qshinoの日記

Powershell関係と徒然なこと

wpf drag and drop powershell

wpf drag and drop by powershell

powershellでのドラックアンドドロップ実装方法。

手順 1. xamlでAllowDrop=“True” 2. PowerShellでハンドラ実装 - Add_DropEnter - Add_DropLeave - その他のハンドラ

AllowDrop

<Window
  Name="w1"
  AllowDrop="True" >
  <StackPanel>
  </StackPanel>
</Window>

ハンドラ

$w : Window Object

function de($sender, $args){
  Wright-Host "Enter"
}

function dl($sender, $args){
  Wright-Host "Leave"
}

function dd($sender, $args){
  Wright-Host "Drop"
  $d = $args.Data.GetData("myformat")
}

# explorerのファイルの場合

function dde($s,$e){
    [string[]]$a = $e.Data.GetData(System.Windows.DataFormats.FileDrop);
  foreach($f in $a){
    Write-Host $f
  }
}


$w.Add_DragEnter( {de $this $_} )
$w.Add_DragLeave({dl $this $_ })
$w.Add_Drop({dde $this $_})

$args : DragEventArgs

参考

http://posaune.hatenablog.com/entry/2012/12/07/220208

https://www.codeproject.com/Articles/43614/Drag-and-Drop-in-WPF

http://www.wpftutorial.net/draganddrop.html

https://msdn.microsoft.com/ja-jp/library/ms742859(v=vs.110).aspx

http://qiita.com/Go-zen-chu/items/c6dbd4c472909118fad0

階層構造 System.Object   System.EventArgs    System.Windows.RoutedEventArgs       System.Windows.DragEventArgs

wpf converter

wpf converter

動作未確認だが、Converterの実装方法を調査中。

xaml

I want to use WPF DataTrigger to check value greater than X. I know that this is only possible with IValueConverter. I have found many C# examples for that, but I need it in powershell. Could someone help me translate this to powershell?

The C# code to translate:

public class CutoffConverter : IValueConverter {
    public object ConvertTo(object obj, Type type) {
        return ((int)obj) > Cutoff;
    }

    public object ConvertFrom(object obj, Type type) {
        throw new NotImplementedException();
    }

    public int Cutoff { get; set; }
}
And the XAML

<Window.Resources>
    <myNamespace:CutoffConverter x:Key="AgeConverter"/>
</Window.Resources>

<DataTemplate.Triggers>
    <DataTrigger Binding="{Binding Path=Age,
                           Converter={StaticResource AgeConverter},
                           ConverterParameter=30}">
        <Setter TargetName="Age" Property="Foreground" Value="Red"/> 
    </DataTrigger>
</DataTemplate.Triggers>

c

$src = @'
using System;
using System.Globalization;
using System.Windows.Data;

namespace MyNamespace
{
    public class CutoffConverter : IValueConverter
    {
        public int Cutoff { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((int)value) > Cutoff;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
'@

Add-Type -AssemblyName PresentationFramework    
Add-Type -TypeDefinition $src -ReferencedAssemblies PresentationFramework

参考

https://stackoverflow.com/questions/14281671/how-to-use-ivalueconverter-from-poweshell

https://social.technet.microsoft.com/Forums/ie/en-US/c54f1c71-3545-4db2-aab2-9c4ce6732c06/how-to-use-ivalueconverter-from-powershell-in-xaml-gui?forum=winserverpowershell

wpf DragDrop FileList

wpf DragDrop

ポイント 1. Window でAllowSrop=“True” 2. PreviewDragOverとDropイベント使用

xaml

Window x:Class="DragFromExplorerSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:DragFromExplorerSample"
        Title="MainWindow" Height="350" Width="525"
        AllowDrop="True"
        Drop="Window_Drop" PreviewDragOver="Window_PreviewDragOver">
    <Window.DataContext>
        <my:MyFileList />
    </Window.DataContext>
    <Grid>
        <ListBox HorizontalAlignment="Stretch"
                 VerticalAlignment="Stretch"
                 ItemsSource="{Binding FileNames}" />
    </Grid>
</Window>
using System.Collections.ObjectModel;
using System.Windows;
namespace DragFromExplorerSample {
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
        private void Window_Drop(object sender, DragEventArgs e) {
            MyFileList list = this.DataContext as MyFileList;
            string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (files != null) {
                foreach (var s in files)
                    list.FileNames.Add(s);
            }
        }
        private void Window_PreviewDragOver(object sender, DragEventArgs e) {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
                e.Effects = DragDropEffects.Copy;
            else
                e.Effects = DragDropEffects.None;
            e.Handled = true;
        }
    }
    public class MyFileList {
        public MyFileList() {
            FileNames = new ObservableCollection<string>();
        }
        public ObservableCollection<string> FileNames {
            get;
            private set;
        }
    }
}

参考

http://gushwell.ldblog.jp/archives/52326682.html

青森

夕方に着いてホテルへ。11Fで綺麗な部屋で快適。有名なのは、帆立味噌焼き、焼き干しラーメン、青森味噌おでん、そして最近流行?の牛乳ラーメン?

まずは帆立味噌焼き。かなりのお店で出しているメニューで、お店毎に違うかもしれないが中々美味しい。とは言え過剰な期待をすると、お店によっては裏切られ感があるかもしれない。

もう1日あるので、都合がつけば他も試してみたい。

盛岡

8/14 盛岡にて

途中に泊まった盛岡。わんこそば、冷麺、じゃじゃ麺と麺ばかりが有名な町。軽く飲んだ後に、名物という事で初めて食べたじゃじゃ麺は、なるほど、他には無く、独自性あり。味噌とにんにく等を自分で混ぜて食べるのだが、食卓に調味料が在るので、それぞれの好みで追加できる。酢とにんにくを増量して食べてみたが、中々美味しい。

翌日、駅で冷やし蕎麦を食べたが、東京と違い蕎麦が黒目で腰があって、これも美味い。山の中で期待していなかったのが功を奏したのか、盛岡の食は中々行けそう。次に来た時は、焼肉と冷麺を試してみたい。

因みに、シンプリシティ盛岡菜園は今一。バスルームの匂いが合わない。傷も所々にあり、ちょっと。

Windows LBFO チーミング

Windows チーミング

Win2012R2以降に実装されたOS標準のチーミング機能。

  • LBFO : Load Balance and Fail Over

チーミングモードは3つ

  1. LACP動的
  2. LAG 静的
  3. スイッチに依存しない

スタンバイアダプター

  1. 個別に指定
  2. 全てアクティブ

負荷分散モード(送信)

  1. 動的
  2. アドレスハッシュモード
  3. IPアドレスPowerShell設定
  4. MACアドレス,PowerShell設定
  5. Hyper-Vポートモード

制限など

  • タグVLANはチームを組んだトランクの中で構成可能。
  • Hyper-VとVLANの同時使用は不可
  • チームメンバーは物理NICのみ。チームとなる仮想NICはメンバーになれない。

スイッチに依存しない

チーミングモードがスイッチに依存しない場合の動作。

補足

タグVLANを使った仮想NICをメンバーとするチーミングが出来ないのが残念。

チーミングメンバーの中でタグVLANを構成できるが、その場合、受信パケットが固定的にプライマリ物理NICとなり、負荷分散が出来ない。

スイッチ冗長構成で、複数スイッチにまたがるLACPができる=スタックできるスイッチが高価なので、スタック出来ないスイッチでスイッチ冗長、かつ、負荷分散するとなるとVLANが不可欠なのだが。

参考

以上

WPF Window Tree列挙

Window要素を列挙、探索

LogicalTreeHelperクラスのGetChildren()メソッドを使う。

public static IEnumerae LogicalTreeHelper.GetChildren(DependencyObject current)

戻り値は、IEnumerable

パラメーター - current Type: System.Windows.DependencyObject The object from which to start processing the logical tree. This is expected to be either a FrameworkElement or FrameworkContentElement. - 戻り値 Type: System.Collections.IEnumerable The enumerable collection of immediate child objects from the logical tree of the specified object.

public static class DependencyObjectExtension
{
    /// <summary>
    /// WalkInChildrenメソッドの本体
    /// </summary>
    /// <param name="obj">DependencyObject</param>
    /// <param name="act">Action</param>
    private static void Walk(DependencyObject obj, Action<DependencyObject> act)
    {
        foreach (var child in LogicalTreeHelper.GetChildren(obj))
        {
            if (child is DependencyObject)
            {
                act(child as DependencyObject);
                Walk(child as DependencyObject, act);
            }
        }
    }

    /// <summary>
    /// 子オブジェクトに対してデリゲートを実行する
    /// </summary>
    /// <param name="obj">this : DependencyObject</param>
    /// <param name="act">デリゲート : Action</param>
    public static void WalkInChildren(this DependencyObject obj, Action<DependencyObject> act)
    {
        if (act == null)
            throw new ArgumentNullException();

        Walk(obj, act);
    }
}

親オブジェクト探索

LogicalTreeHelper.GetParent(DepandencyObject)

名前探索

.FindName(name)

探索方法

  • 名前探索 FindName()
  • 子を全て列挙 GetChildren()
  • ルートウインドウ探索 GetParent()の繰り返し。
  • 所属エレメント列挙 GetParent()でルートを見つけてGetChildren()
  • 所属エレメント列挙、ルートの名前が分かっている FindName(ルートの名前)でルートを見つけてGetChildren()で列挙。

参考