国際音声記号

国際音声記号を、集めてみました。

 

軟口蓋鼻音
ŋ
IPA 番号 119
IPA 表記 [ŋ]
IPA 画像 Xsampa-N2.png
Unicode U+014B
文字参照 ŋ
JIS X 0213 1-10-90
X-SAMPA N
Kirshenbaum N
 
メニュー
 
 
 
 

wpfの直訳

wpf(および、C#)の用語や、クラス名を、直訳してみました。

 

binding 装丁
dependency 依存
dispatcher 発送係
trigger 引き金
property 資産
event イベント
delegate 代表
routed 送られます
command 命令
window ウインドウ
control 支配
content 内容
presenter プレゼンター
element 要素
framework フレームワーク
brush ブラシ
color 色
geometry 幾何学
cache キャッシュ
alignment 調整
segment 部分
converter コンバータ
character 性格
composition 構成
style スタイル
image イメージ
drawing スケッチ
context 前後関係
group グループ
visual ビジュアル
exception 例外
glyph シンボル
gradient 勾配
transform 変えてください
timeline スケジュール
media メディア
path 経路
collection 収集
pixel ピクセル
effect 影響

wpf DomainUpDownコントロール

wpfの、DomainUpDownコントロールを、作ってみました。

 

まずは、コードです。

 

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Controls.Primitives;

namespace OkaSharp
{

 

[TemplatePart(Name = "PART_UpButton", Type = typeof(RepeatButton))]
[TemplatePart(Name = "PART_DownButton", Type = typeof(RepeatButton))]
[TemplateVisualState(Name = "Focused", GroupName = "FocusedStates")]
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusedStates")]
public class DomainUpDown : Selector
{
static DomainUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DomainUpDown), new FrameworkPropertyMetadata(typeof(DomainUpDown)));
}

public DomainUpDown()
{
DefaultStyleKey = typeof(DomainUpDown);
this.IsTabStop = true;
}

 


private void UpdateStates(bool useTransitions)
{

if (IsFocused)
{
VisualStateManager.GoToState(this, "Focused", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Unfocused", useTransitions);
}

}

public override void OnApplyTemplate()
{
UpButtonElement = GetTemplateChild("PART_UpButton") as RepeatButton;
DownButtonElement = GetTemplateChild("PART_DownButton") as RepeatButton;
//TextElement = GetTemplateChild("TextBlock") as TextBlock;

UpdateStates(false);
}

private RepeatButton downButtonElement;

private RepeatButton DownButtonElement
{
get
{
return downButtonElement;
}

set
{
if (downButtonElement != null)
{
downButtonElement.Click -=
new RoutedEventHandler(downButtonElement_Click);
}
downButtonElement = value;

if (downButtonElement != null)
{
downButtonElement.Click +=
new RoutedEventHandler(downButtonElement_Click);
}
}
}

void downButtonElement_Click(object sender, RoutedEventArgs e)
{

if*1
SelectedIndex--;
}

private RepeatButton upButtonElement;

private RepeatButton UpButtonElement
{
get
{
return upButtonElement;
}

set
{
if (upButtonElement != null)
{
upButtonElement.Click -=
new RoutedEventHandler(upButtonElement_Click);
}
upButtonElement = value;

if (upButtonElement != null)
{
upButtonElement.Click +=
new RoutedEventHandler(upButtonElement_Click);
}
}
}

void upButtonElement_Click(object sender, RoutedEventArgs e)
{
if *2
SelectedIndex++;
}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
Focus();
}


protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
UpdateStates(true);
}

protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
UpdateStates(true);
}
}

 

}

 

次に、スタイルです。

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OkaSharp">

<Style TargetType="{x:Type local:DomainUpDown}" x:Key="{x:Type local:DomainUpDown}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:DomainUpDown">
<Grid Background="{TemplateBinding Background}">


<VisualStateManager.VisualStateGroups>

 

<VisualStateGroup Name="FocusStates">


<VisualState Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0"
Storyboard.TargetName="FocusVisual"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>

<!--
Return the control to its initial state by
hiding the focus rectangle.
-->
<VisualState Name="Unfocused" />
</VisualStateGroup>

</VisualStateManager.VisualStateGroups>

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25" />
</Grid.ColumnDefinitions>

<Border Grid.RowSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="#E0FFFFFF"
BorderBrush="Gray"
BorderThickness="1">

Content="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type local:DomainUpDown}},
Path=SelectedItem}"
Padding="0"


/>
</Border>

<Rectangle Name="FocusVisual"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
Stroke="Black"
StrokeDashArray="0,1"
StrokeThickness="1"
Visibility="Collapsed" />
<RepeatButton Name="PART_UpButton"
Grid.Row="0"
Grid.Column="1"
Content="▲"
FontSize="8" />
<RepeatButton Name="PART_DownButton"
Grid.Row="1"
Grid.Column="1"
Content="▼"
FontSize="8" />

</Grid>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>

 

 

 

 

 

*1:SelectedIndex > 0

*2:SelectedIndex < Items.Count - 1

wpfのDropDownButton

office等で、よく見る、DropDownButtonを、このブログでは、DropDownButtonと、DropDownMenuButtonと、

DDButtonの、3通りの呼び方をします。

 

それを、wpfで、作ってみました。

 

まずは、コードです。

 

using System;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace OkaSharp
{

 

/// <summary>
/// ドロップ ダウン メニューを表示する為のボタン コントロール クラスです。
/// </summary>
///
[TemplatePart(Name = "PART_DropDownButton", Type = typeof(ToggleButton))]
public sealed class DropDownButton : Control
{

static DropDownButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DropDownButton), new FrameworkPropertyMetadata(typeof(DropDownButton)));
}

/// <summary>
/// インスタンスを初期化します。
/// </summary>
public DropDownButton()
{

}

public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(
"Content", typeof(object), typeof(DropDownButton),
new PropertyMetadata(((Object)"")));

public object Content
{
get
{
return (object)GetValue(ContentProperty);
}

set
{


SetValue(ContentProperty, value);

 

}
}

public static readonly DependencyProperty DropDownContentProperty =
DependencyProperty.Register(
"DropDownContent", typeof(object), typeof(DropDownButton),
new PropertyMetadata(((Object)"")));

public object DropDownContent
{
get
{
return (object)GetValue(DropDownContentProperty);
}

set
{


SetValue(DropDownContentProperty, value);

 

}
}

private void UpdateStates(bool useTransitions)
{


}

public override void OnApplyTemplate()
{

DropDownButtonElement = GetTemplateChild("PART_DropDownButton") as ToggleButton;


UpdateStates(false);
}

private ToggleButton dropDownButtonElement;

private ToggleButton DropDownButtonElement
{
get
{
return dropDownButtonElement;
}

set
{
if (dropDownButtonElement != null)
{
dropDownButtonElement.Click -=
new RoutedEventHandler(dropDownButtonElement_Click);
}
dropDownButtonElement = value;

if (dropDownButtonElement != null)
{
dropDownButtonElement.Click +=
new RoutedEventHandler(dropDownButtonElement_Click);
}
}
}

void dropDownButtonElement_Click(object sender, RoutedEventArgs e)
{

}

 

/// <summary>
/// ドロップ ダウンとして表示するメニューを表す依存プロパティです。
/// </summary>
public static readonly DependencyProperty DropDownContextMenuProperty = DependencyProperty.Register("DropDownContextMenu", typeof(ContextMenu), typeof(DropDownButton), new UIPropertyMetadata(null));
}

 

}

 

次に、スタイルです。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OkaSharp"
>

 

<Style x:Key="{x:Type local:DropDownButton}" TargetType="{x:Type local:DropDownButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:DropDownButton">
<Grid Background="{TemplateBinding Background}">

 


<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>


<ToggleButton Name="PART_DropDownButton"
Grid.Row="0"
Grid.Column="0">
<StackPanel Orientation="Horizontal">
<ContentPresenter Content="{TemplateBinding Content}" />

<TextBlock Text="▼" />
</StackPanel>
</ToggleButton>

 

</Grid>
<Popup AllowsTransparency="True"
Focusable="False"
HorizontalOffset="1"
IsOpen="{Binding Path=IsChecked,
ElementName=PART_DropDownButton}"
Placement="Bottom"
StaysOpen="False"
VerticalOffset="1">
<Border Background="White" BorderBrush="Gray">
<ContentPresenter Content="{TemplateBinding DropDownContent}" />

</Border>
</Popup>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

 

</ResourceDictionary>

wpfのNumericUpDown

NumericUpDownは、wpfのカスタムコントロールの、定番ですよね。

それも、作ってみました。

 

まずは、コードです。

 

using System;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

using System.Windows.Input;

using System.Windows.Controls.Primitives;

namespace OkaSharp
{

[TemplatePart(Name = "PART_UpButton", Type = typeof(RepeatButton))]
[TemplatePart(Name = "PART_DownButton", Type = typeof(RepeatButton))]
[TemplateVisualState(Name = "Positive", GroupName = "ValueStates")]
[TemplateVisualState(Name = "Negative", GroupName = "ValueStates")]
[TemplateVisualState(Name = "Focused", GroupName = "FocusedStates")]
[TemplateVisualState(Name = "Unfocused", GroupName = "FocusedStates")]
public class NumericUpDown : Control
{
static NumericUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), new FrameworkPropertyMetadata(typeof(NumericUpDown)));
}

public NumericUpDown()
{
DefaultStyleKey = typeof(NumericUpDown);
this.IsTabStop = true;
}


public static readonly DependencyProperty MaxValueProperty =
DependencyProperty.Register(
"MaxValue", typeof(double), typeof(NumericUpDown),
new PropertyMetadata(100.0,
new PropertyChangedCallback(ValueChangedCallback)));

public double MaxValue
{
get
{
return (double)GetValue(MaxValueProperty);
}

set
{
SetValue(MaxValueProperty, value);

}
}

public static readonly DependencyProperty MinValueProperty =
DependencyProperty.Register(
"MinValue", typeof(double), typeof(NumericUpDown),
new PropertyMetadata(-100.0,
new PropertyChangedCallback(ValueChangedCallback)));

public double MinValue
{
get
{
return (double)GetValue(MinValueProperty);
}

set
{
SetValue(MinValueProperty, value);

}
}

 

public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(
"Value", typeof(double), typeof(NumericUpDown),
new PropertyMetadata(0.0,
new PropertyChangedCallback(ValueChangedCallback)));

public double Value
{
get
{
return (double)GetValue(ValueProperty);
}

set
{
if *1
{

SetValue(ValueProperty, value);

}
else if(value > MaxValue)
{

SetValue(ValueProperty, MaxValue);
}
else if(value < MinValue)
{
SetValue(ValueProperty, MinValue);
}

}
}

private static void ValueChangedCallback(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
NumericUpDown ctl = (NumericUpDown)obj;
double newValue = (double)args.NewValue;

// Call UpdateStates because the Value might have caused the
// control to change ValueStates.
ctl.UpdateStates(true);

// Call OnValueChanged to raise the ValueChanged event.
ctl.OnValueChanged(
new System.Windows.RoutedPropertyChangedEventArgs<double>*2;
}

public static readonly RoutedEvent ValueChangedEvent =
EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Direct,
typeof(System.Windows.RoutedPropertyChangedEventHandler<double>), typeof(NumericUpDown));

public event System.Windows.RoutedPropertyChangedEventHandler<double> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}


protected virtual void OnValueChanged(System.Windows.RoutedPropertyChangedEventArgs<double> e)
{
// Raise the ValueChanged event so applications can be alerted
// when Value changes.
RaiseEvent(e);
}


private void UpdateStates(bool useTransitions)
{
if (Value >= 0)
{
VisualStateManager.GoToState(this, "Positive", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Negative", useTransitions);
}

if (IsFocused)
{
VisualStateManager.GoToState(this, "Focused", useTransitions);
}
else
{
VisualStateManager.GoToState(this, "Unfocused", useTransitions);
}

}

public override void OnApplyTemplate()
{
UpButtonElement = GetTemplateChild("PART_UpButton") as RepeatButton;
DownButtonElement = GetTemplateChild("PART_DownButton") as RepeatButton;
//TextElement = GetTemplateChild("TextBlock") as TextBlock;

UpdateStates(false);
}

private RepeatButton downButtonElement;

private RepeatButton DownButtonElement
{
get
{
return downButtonElement;
}

set
{
if (downButtonElement != null)
{
downButtonElement.Click -=
new RoutedEventHandler(downButtonElement_Click);
}
downButtonElement = value;

if (downButtonElement != null)
{
downButtonElement.Click +=
new RoutedEventHandler(downButtonElement_Click);
}
}
}

void downButtonElement_Click(object sender, RoutedEventArgs e)
{
Value--;
}

private RepeatButton upButtonElement;

private RepeatButton UpButtonElement
{
get
{
return upButtonElement;
}

set
{
if (upButtonElement != null)
{
upButtonElement.Click -=
new RoutedEventHandler(upButtonElement_Click);
}
upButtonElement = value;

if (upButtonElement != null)
{
upButtonElement.Click +=
new RoutedEventHandler(upButtonElement_Click);
}
}
}

void upButtonElement_Click(object sender, RoutedEventArgs e)
{
Value++;
}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
Focus();
}


protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
UpdateStates(true);
}

protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
UpdateStates(true);
}
}

}

 

次に、スタイルです。

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OkaSharp"
>

 

<Style TargetType="{x:Type local:NumericUpDown}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:NumericUpDown">
<Grid Background="{TemplateBinding Background}">


<VisualStateManager.VisualStateGroups>

 

<VisualStateGroup Name="FocusStates">

<!--
Add a focus rectangle to highlight the entire control
when it has focus.
-->
<VisualState Name="Focused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0"
Storyboard.TargetName="FocusVisual"
Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>

<!--
Return the control to its initial state by
hiding the focus rectangle.
-->
<VisualState Name="Unfocused" />
</VisualStateGroup>

</VisualStateManager.VisualStateGroups>

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25" />
</Grid.ColumnDefinitions>

<Border Grid.RowSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="#E0FFFFFF"
BorderBrush="Gray"
BorderThickness="1">
<!-- Bind the TextBlock to the Value property -->
<TextBlock Name="TextBlock"
Text="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type local:NumericUpDown}},
Path=Value}"
TextAlignment="Right" />
</Border>

<Rectangle Name="FocusVisual"
Grid.RowSpan="2"
Grid.ColumnSpan="2"
Stroke="Black"
StrokeDashArray="0,1"
StrokeThickness="1"
Visibility="Collapsed" />
<RepeatButton Name="PART_UpButton"
Grid.Row="0"
Grid.Column="1"
Content="▲"
FontSize="8" />
<RepeatButton Name="PART_DownButton"
Grid.Row="1"
Grid.Column="1"
Content="▼"
FontSize="8" />

</Grid>

</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

 

 

</ResourceDictionary>

 

*1:value <= MaxValue) && (value >= MinValue

*2:double)(args.OldValue),
newValue, ValueChangedEvent

ワードの下線ボタン

ワードの下線ボタンって、スプリットボタンでもなく、トグルボタンでもなく、その両方ですよね。

そこで、wpfで、それを作ってみました。(名称は、SplitToggleButtonです。)

 

まずは、コードです。

 

using System;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

using System.Windows.Input;

using System.Windows.Controls.Primitives;


namespace OkaSharp
{

[TemplatePart(Name = "PART_ToggleButton", Type = typeof(ToggleButton))]
[TemplatePart(Name = "PART_DropDownButton", Type = typeof(ToggleButton))]
public class SplitToggleButton : Control
{
static SplitToggleButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SplitToggleButton), new FrameworkPropertyMetadata(typeof(SplitToggleButton)));
}

public SplitToggleButton()
{
DefaultStyleKey = typeof(SplitToggleButton);
this.IsTabStop = true;

var binding = new Binding("DropDownContextMenu.IsOpen") { Source = DropDownButtonElement };
this.SetBinding(ToggleButton.IsCheckedProperty, binding);
}

public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(
"Content", typeof(object), typeof(SplitToggleButton),
new PropertyMetadata(((Object)"")));

public object Content
{
get
{
return (object)GetValue(ContentProperty);
}

set
{


SetValue(ContentProperty, value);

 

}
}


public static readonly DependencyProperty DropDownContentProperty =
DependencyProperty.Register(
"DropDownContent", typeof(object), typeof(SplitToggleButton),
new PropertyMetadata(((Object)"")));


public object DropDownContent
{
get
{
return (object)GetValue(DropDownContentProperty);
}

set
{


SetValue(DropDownContentProperty, value);

 

}
}

public static readonly DependencyProperty IsCheckedProperty =
DependencyProperty.Register(
"IsChecked", typeof(bool), typeof(SplitToggleButton),
new PropertyMetadata(false, new PropertyChangedCallback(IsCheckedChangedCallback)));

public bool IsChecked
{
get
{
return (bool)GetValue(IsCheckedProperty);
}

set
{


SetValue(IsCheckedProperty, value);

 

}
}

private static void IsCheckedChangedCallback(DependencyObject obj,
DependencyPropertyChangedEventArgs args)
{
SplitToggleButton ctl = (SplitToggleButton)obj;
bool newValue = (bool)args.NewValue;

// Call UpdateStates because the Value might have caused the
// control to change ValueStates.
ctl.UpdateStates(true);

// Call OnValueChanged to raise the ValueChanged event.

if (newValue == true)
{
ctl.OnIsCheckedChanged(
new System.Windows.RoutedEventArgs(CheckedEvent));
}
else if(newValue == false)
{

ctl.OnIsCheckedChanged(
new System.Windows.RoutedEventArgs(UncheckedEvent));

}


ctl.ToggleButtonElement.IsChecked = newValue;


}

public static readonly RoutedEvent CheckedEvent =
EventManager.RegisterRoutedEvent("Checked", RoutingStrategy.Direct,
typeof(System.Windows.RoutedEventHandler), typeof(SplitToggleButton));

/// <summary>
/// チェックされたときに発生
/// </summary>
public event System.Windows.RoutedEventHandler CheckedChanged
{
add { AddHandler(CheckedEvent, value); }
remove { RemoveHandler(CheckedEvent, value); }
}

public static readonly RoutedEvent UncheckedEvent =
EventManager.RegisterRoutedEvent("Unchecked", RoutingStrategy.Direct,
typeof(System.Windows.RoutedEventHandler), typeof(SplitToggleButton));

/// <summary>
/// チェックされたときに発生
/// </summary>
public event System.Windows.RoutedEventHandler UncheckedChanged
{
add { AddHandler(UncheckedEvent, value); }
remove { RemoveHandler(UncheckedEvent, value); }
}


protected virtual void OnIsCheckedChanged(System.Windows.RoutedEventArgs e)
{
// Raise the ValueChanged event so applications can be alerted
// when Value changes.
RaiseEvent(e);
}


/// <summary>
/// ドロップ ダウンとして表示するコンテキスト メニューを取得または設定します。
/// </summary>

 

private void UpdateStates(bool useTransitions)
{


}

public override void OnApplyTemplate()
{
ToggleButtonElement = GetTemplateChild("PART_ToggleButton") as ToggleButton;
DropDownButtonElement = GetTemplateChild("PART_DropDownButton") as ToggleButton;
//TextElement = GetTemplateChild("TextBlock") as TextBlock;

UpdateStates(false);
}

private ToggleButton toggleButtonElement;

private ToggleButton ToggleButtonElement
{
get
{
return toggleButtonElement;
}

set
{
if (toggleButtonElement != null)
{
toggleButtonElement.Click -=
new RoutedEventHandler(toggleButtonElement_Click);

toggleButtonElement.Checked -= ToggleButtonElement_Checked;

toggleButtonElement.Unchecked -= ToggleButtonElement_Unchecked;
}
toggleButtonElement = value;

if (toggleButtonElement != null)
{
toggleButtonElement.Click +=
new RoutedEventHandler(toggleButtonElement_Click);

toggleButtonElement.Checked += ToggleButtonElement_Checked;

toggleButtonElement.Unchecked += ToggleButtonElement_Unchecked;
}
}
}

private void ToggleButtonElement_Unchecked(object sender, RoutedEventArgs e)
{
this.IsChecked = false;
}

private void ToggleButtonElement_Checked(object sender, RoutedEventArgs e)
{
this.IsChecked = true;
}

void toggleButtonElement_Click(object sender, RoutedEventArgs e)
{

}

private ToggleButton dropDownButtonElement;

private ToggleButton DropDownButtonElement
{
get
{
return dropDownButtonElement;
}

set
{
if (dropDownButtonElement != null)
{
dropDownButtonElement.Click -=
new RoutedEventHandler(dropDownButtonElement_Click);
}
dropDownButtonElement = value;

if (dropDownButtonElement != null)
{
dropDownButtonElement.Click +=
new RoutedEventHandler(dropDownButtonElement_Click);
}
}
}

void dropDownButtonElement_Click(object sender, RoutedEventArgs e)
{

}

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
Focus();
}


protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
UpdateStates(true);
}

protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
UpdateStates(true);
}
}

 

次に、スタイルです。

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OkaSharp"
>

<Style x:Key="{x:Type local:SplitToggleButton}" TargetType="{x:Type local:SplitToggleButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:SplitToggleButton">
<Grid Background="{TemplateBinding Background}">

 


<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>


<ToggleButton Name="PART_ToggleButton"
Grid.Row="0"
Grid.Column="0"
Content="{TemplateBinding Content}" />
<ToggleButton Name="PART_DropDownButton"
Grid.Row="0"
Grid.Column="1"
Content="▼" />

 

</Grid>

<Popup AllowsTransparency="True"
Focusable="False"
HorizontalOffset="1"
IsOpen="{Binding Path=IsChecked,
ElementName=PART_DropDownButton}"
Placement="Bottom"
StaysOpen="False"
VerticalOffset="1">
<Border Background="White" BorderBrush="Gray">
<ContentPresenter Content="{TemplateBinding DropDownContent}" />

</Border>
</Popup>


</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>

 

 

}