Skip to content

Instantly share code, notes, and snippets.

@pinzolo
pinzolo / gist:2952468
Created June 19, 2012 05:39
HierarchicalDataTemplate な TreeViewItem にイベントを設定する
<Window x:Class="MktSys.Gui.HierarchicalDataTemplateTreeViewItemEventSettingWindos"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HierarchicalDataTemplate な TreeViewItem にイベントを設定する" Height="525" Width="300">
<Grid>
<TreeView Name="treeView" ItemsSource="{Binding Elements}" VerticalContentAlignment="Stretch">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="treeViewItem_MouseDoubleClick" />
</Style>
@pinzolo
pinzolo / gist:2958770
Created June 20, 2012 08:17
DependencyObject拡張クラス
using System.Windows;
using System.Windows.Media;
namespace MktSys.Lib.Extensions
{
/// <summary>
/// DependencyObject 拡張メソッドクラス
/// </summary>
public static class DependencyObjectExtension
{
@pinzolo
pinzolo / gist:2970346
Created June 22, 2012 05:03
サクラエディタ用C#キーワードファイル
// C# キーワード定義ファイル
// CASE=True
#endif
#endregion
#if
#pragma
#region
abstract
as
@pinzolo
pinzolo / gist:2970686
Created June 22, 2012 06:07
[WPF]TreeViewでのドラッグアンドドロップ
// HierarchicalDataTemplate を使用して、様々な TreeItemViewModelBase を継承したクラスを含むツリーでのドラッグアンドドロップを想定。
// typeof で実際にドラッグされたアイテムの Type を指定できないため、ホルダーを作成している。
/// <summary>
/// 最後に左クリックした座標
/// </summary>
private Point lastLeftMouseButtonDownPoint;
/// <summary>
/// ドラッグアンドドロップ開始基準となる距離
@pinzolo
pinzolo / gist:3003270
Created June 27, 2012 10:50
[WPF]DataGrid のセルに存在するコントロールを取得する
using System.Windows.Controls.Primitives;
this.dataGrid.Items.ForEach<DataGridRowViewModel>(viewModel =>
{
var dataGridRow = this.dataGrid.ItemContainerGenerator.ContainerFromItem(viewModel) as DataGridRow;
var cellsPresenter = dataGridRow.FindVisualChild<DataGridCellsPresenter>();
var cell = cellsPresenter.ItemContainerGenerator.ContainerFromItem(viewModel) as DataGridCell;
var presenter = cell.Content as ContentPresenter;
var dbOutputValueTextBox = presenter.ContentTemplate.FindName("valueTextBox", presenter) as TextBox;
viewModel.Value = valueTextBox.Text;
@pinzolo
pinzolo / gist:3080473
Created July 10, 2012 01:41
[WPF]TextBox に文字列以外をドロップする
// PreviewDragOver で捕まえないとダメ
/// <summary>
/// TextBox ドラッグオーバー時処理<br />
/// 対象のアイテムならば受け入れる。
/// </summary>
/// <param name="sender">発生元</param>
/// <param name="e">引数</param>
private void textBox_PreviewDragOver(object sender, DragEventArgs e)
{
@pinzolo
pinzolo / gist:3080481
Created July 10, 2012 01:44
[WPF]コントロールキーあるいはシフトキーが押されているかどうかを取得する
/// <summary>
/// コントロールキーあるいはシフトキーが押されているかどうかを取得する
/// </summary>
private bool IsCtrlOrShiftKeyPressed
{
get
{
return (Keyboard.GetKeyStates(Key.LeftShift) & KeyStates.Down) == KeyStates.Down ||
(Keyboard.GetKeyStates(Key.RightShift) & KeyStates.Down) == KeyStates.Down ||
(Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) == KeyStates.Down ||
@pinzolo
pinzolo / gist:3103668
Created July 13, 2012 08:33
[WPF]コンテキストメニューのバインディングにてセパレータを動的に生成する
<ContextMenu ItemsSource="{Binding Menus}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Title}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSeparator}" Value="True">
<Setter Property="Template">
<Setter.Value>
@pinzolo
pinzolo / gist:3486769
Created August 27, 2012 08:56
[WPF]WindowStyle が None なウィンドウを ALT+TAB で表示させないようにする
public class Native
{
[Flags]
public enum ExtendedWindowStyles
{
WS_EX_TOOLWINDOW = 0x80
}
public enum GetWindowLongFields
{
@pinzolo
pinzolo / gist:3663046
Created September 7, 2012 04:09
[WPF]ウィンドウをデスクトップの任意の位置に表示させる
// System.Windows.Forms と System.Drawing を参照設定に追加する必要がある。
// この例では通知ウィンドウを右下に表示させるというシナリオ
/// <summary>
/// 通知ウィンドウ表示時の画面からのマージン
/// </summary>
private const int NOTIFICATION_WINDOW_DISPLAY_MARGIN = 5;
/// <summary>
/// 指定のメッセージをユーザーに知らせるダイアログを表示する。