動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
関連
- Visual Studio | WPF > カスタム添付プロパティの使用例 | link:AttachedPropertyBrowsableForType
- Visual Studio | WPF > カスタム添付プロパティ > AttachedPropertyBrowsableForType > Getには指定して、Setには指定しない
AttachedPropertyBrowsableForType の効果
[AttachedPropertyBrowsableForType(typeof(TextBox))]
public static bool GetIsNumeric(DependencyObject obj)
{
return (bool)obj.GetValue(IsNumericProperty);
}
AttachedPropertyBrowsableForType(typeof(TextBox))
の効果とは何か。
A visual designer typically displays in the Properties window those members that either have no browsable attribute or are marked with the BrowsableAttribute constructor's browsable parameter set to true.
デザイン時にプロパティウィンドウに表示されるかどうかということのようだ。
試してみた
以下の2つのコントロールにTextBoxBehaviors.IsNumeric
プロパティを設定した。
- TextBox
- Button
MainWindow.xaml
<Window x:Class="_171207_t1930_behavior.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_171207_t1930_behavior"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<TextBox Name="textBox1" Height="23" Width="120"
local:TextBoxBehaviors.IsNumeric="True"/>
<Button Name="Button1" local:TextBoxBehaviors.IsNumeric="True" Height="30"/>
</StackPanel>
</Grid>
</Window>
プロパティのウィンドウでTextBoxBehaviors.IsNumeric
が見つかるか調べた。