2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Visual Studio | WPF > カスタム添付プロパティ > AttachedPropertyBrowsableForType の効果 > デザイン時にプロパティウィンドウに表示するかどうか

Last updated at Posted at 2017-12-08
動作環境
Windows 8.1 Pro (64bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

関連

AttachedPropertyBrowsableForType の効果

       [AttachedPropertyBrowsableForType(typeof(TextBox))]
        public static bool GetIsNumeric(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsNumericProperty);
        }

AttachedPropertyBrowsableForType(typeof(TextBox))の効果とは何か。

BrowsableAttribute クラス

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が見つかるか調べた。

TextBoxで検索 (見つかる)
qiita.png

Buttonで検索 (見つからない)
qiita.png

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?