Button クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
タッチ イベントに反応するボタン View。
[Xamarin.Forms.RenderWith(typeof(Xamarin.Forms.Platform._ButtonRenderer))]
public class Button : Xamarin.Forms.View, Xamarin.Forms.IBorderElement, Xamarin.Forms.IButtonController, Xamarin.Forms.IElementConfiguration<Xamarin.Forms.Button>, Xamarin.Forms.IImageController, Xamarin.Forms.IImageElement, Xamarin.Forms.Internals.IFontElement
type Button = class
inherit View
interface IFontElement
interface IBorderElement
interface IButtonController
interface IViewController
interface IVisualElementController
interface IElementController
interface IElementConfiguration<Button>
interface IImageController
interface IImageElement
- 継承
- 属性
- 実装
注釈
Button Appearance
In addition to the appearance properties common to all View objects, the Button class provides the BorderColor, BorderWidth, BorderRadius, and Image properties.
The XAML code snippet below demonstrates how to use these properties to create a basic button with the text "Press me!" The image that the button displays appears on the start side of the layout, which is the left side for left-to-right languages.
<Button Text="Press me!"
Image="icon.png"
BackgroundColor="White"
BorderRadius="10"
BorderWidth="2"
BorderColor="Black"
HorizontalOptions="Center"/>
To display the icon.png image with the above XAML, the developer must place it in the appropriate location, with the appropriate build action, specific to each platform project. The Images topic explains this and other important details about working with images in Xamarin.Forms.
Button Events
Buttons notify the developer of press, release, and click events with the Pressed, Released, and Clicked events, respectively.
The following XAML assigns handlers to two of these button events:
<Button x:Name="PressMeButton"
Text="Press Me!"
Pressed="PressMeButton_Pressed"
Clicked="PressMeButton_Clicked"/>
With the XAML above, the following event handlers in the code-behind file change the button's text when these events are raised:
private void PressMeButton_Pressed(object sender, EventArgs e)
{
(sender as Button).Text = "You pressed me!";
}
private void PressMeButton_Clicked(object sender, EventArgs e)
{
(sender as Button).Text = "I was just clicked!";
}
Commands
The commanding API for buttons allows the developer to run a command in response to what would otherwise be the Clicked event.
The following XAML specifes a command to run when the button is clicked. The command updates a view model property called modelUpdateCount, which the button then uses to update its text. (The text binding is shown for completeness. Only the commanding code is relevant.):
<Button Text="{Binding modelUpdateCount, StringFormat='Number of updates to the model: {0:D}'}"
Command="{Binding IncrementLabelCommand}" />
With the XAML above, the developer first defines the IncrementLabelCommand property on the view model and implements a method with which to later instantiate the command:
public ICommand IncrementLabelCommand { get; private set; }
void IncrementLabel()
{
modelUpdateCount++;
}
Second, the developer initializes the command with the method (or action):
public ViewModelDemo()
{
IncrementLabelCommand = new Command(IncrementLabel);
}
Finally, the developer must sets the binding context in the constructor for the main page to that of the view model where the property is implemented:
public MainPage()
{
InitializeComponent();
BindingContext = new ViewModelDemo();
}
コンストラクター
| Button() |
Button クラスの新しいインスタンスを初期化します。 |
フィールド
| BorderColorProperty |
バインド可能なプロパティ BorderColor のバッキング ストア。 |
| BorderRadiusProperty |
互換性のために残されています。
バインド可能なプロパティ BorderRadius のバッキング ストア。 |
| BorderWidthProperty |
バインド可能なプロパティ BorderWidth のバッキング ストア。 |
| CharacterSpacingProperty |
バインド可能なプロパティ CharacterSpacing のバッキング ストア。 |
| CommandParameterProperty |
バインド可能なプロパティ CommandParameter のバッキング ストア。 |
| CommandProperty |
バインド可能なプロパティ Command のバッキング ストア。 |
| ContentLayoutProperty |
バインド可能なプロパティ ContentLayout のバッキング ストア。 |
| CornerRadiusProperty |
バインド可能なプロパティ CornerRadius のバッキング ストア。 |
| FontAttributesProperty |
バインド可能なプロパティ FontAttributes のバッキング ストア。 |
| FontFamilyProperty |
バインド可能なプロパティ FontFamily のバッキング ストア。 |
| FontProperty |
バインド可能なプロパティ Font のバッキング ストア。 |
| FontSizeProperty |
バインド可能なプロパティ FontSize のバッキング ストア。 |
| ImageProperty |
互換性のために残されています。
バインド可能なプロパティ Image のバッキング ストア。 |
| ImageSourceProperty |
バインド可能なプロパティ ImageSource のバッキング ストア。 |
| IsPressedProperty |
バインド可能なプロパティ IsPressed のバッキング ストア。 |
| PaddingProperty |
バインド可能なプロパティ Padding のバッキング ストア。 |
| TextColorProperty |
バインド可能なプロパティ TextColor のバッキング ストア。 |
| TextProperty |
バインド可能なプロパティ Text のバッキング ストア。 |
| TextTransformProperty |
バインド可能なプロパティ TextTransform のバッキング ストア。 |
プロパティ
| AnchorX |
すべての変換の中心点の X 座標を、要素の境界からの相対位置で取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| AnchorY |
すべての変換の中心点の Y 座標を、要素の境界からの相対位置で取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| AutomationId |
自動化フレームワークがこの要素を見つけ、対話することを可能にする値を取得または設定します。 (継承元 Element) |
| Background | (継承元 VisualElement) |
| BackgroundColor |
VisualElement の背景を塗りつぶす色を取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| Batched |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| Behaviors |
この要素に関連付けられている動作の一覧を取得します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| BindingContext |
バインドされたプロパティのうち、この BindableObject に属するプロパティの対象となるプロパティが含まれるオブジェクトを取得または設定します。 (継承元 BindableObject) |
| BorderColor |
ボタンの境界線のストローク色を表す色を取得または設定します。 これはバインド可能なプロパティです。 |
| BorderRadius |
互換性のために残されています。
境界線の角の半径を取得または設定します。 これはバインド可能なプロパティです。 |
| BorderWidth |
境界線の幅を取得または設定します。 これはバインド可能なプロパティです。 |
| Bounds |
要素の範囲を取得します。 (継承元 VisualElement) |
| CharacterSpacing | |
| class | (継承元 NavigableElement) |
| ClassId |
意味的に同類の要素の集合を識別するために使用される値を取得または設定します。 (継承元 Element) |
| Clip | (継承元 VisualElement) |
| Command |
このボタンがアクティブになったときに呼び出すコマンドを取得または設定します。 これはバインド可能なプロパティです。 |
| CommandParameter |
Command プロパティに渡すパラメーターを取得または設定します。 これはバインド可能なプロパティです。 |
| ContentLayout |
ボタン画像の位置と、ボタン画像とボタンテキストの間隔を制御するオブジェクトを取得または設定します。 |
| CornerRadius |
デバイス非依存ユニットでボタンの角の半径を取得または設定します。 |
| DisableLayout |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| Dispatcher | (継承元 BindableObject) |
| EffectControlProvider |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 Element) |
| Effects |
この項目に適用される効果の一覧。 (継承元 Element) |
| FlowDirection |
レイアウトのフロー方向を取得または設定します。 (継承元 VisualElement) |
| Font |
ラベル テキストのフォントを取得または設定します。 これはバインド可能なプロパティです。 |
| FontAttributes |
ボタン テキストのフォントが太字か、斜体か、そのいずれでもないかを示す値を取得します。 |
| FontFamily |
ボタン テキストのフォントが属するフォント ファミリを取得します。 |
| FontSize |
ボタン テキストのフォントのサイズを取得または設定します。 |
| GestureController |
ビューのジェスチャのコントローラーを取得します。 (継承元 View) |
| GestureRecognizers |
このビューに関連付けられているジェスチャ レコグナイザーのコレクション。 (継承元 View) |
| Height |
この要素の描画時の現在の高さを取得します。 これはバインド可能な読み取り専用プロパティです。 (継承元 VisualElement) |
| HeightRequest |
この要素の必要な高さオーバーライドを取得または設定します。 (継承元 VisualElement) |
| HorizontalOptions |
レイアウト サイクルで要素がどのように配置されるかを定義する LayoutOptions を取得または設定します。 これはバインド可能なプロパティです。 (継承元 View) |
| Id |
アプリケーションの実行により要素を一意に識別するために使用できる値を取得します。 (継承元 Element) |
| Image |
互換性のために残されています。
ボタンのテキストの隣に表示される任意の画像ソースを取得または設定します。 これはバインド可能なプロパティです。 |
| ImageSource |
ボタンのビットマップ画像を表示します。 |
| InputTransparent |
この要素をユーザー インターフェイス サイクルに含めるかどうかを示す値を取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| IsEnabled |
この要素をユーザー インターフェイスで有効にするかどうかを示す値を取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| IsFocused |
この要素に現在フォーカスがあるかどうかを示す値を取得します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| IsInNativeLayout |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| IsNativeStateConsistent |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| IsPlatformEnabled |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| IsPressed |
Xamarin.Forms プラットフォームによる内部使用向け。 |
| IsTabStop |
この要素がタブ ナビゲーションに含まれるかどうかを示す値を取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| IsVisible |
要素をビジュアル ツリーに含めるかどうかを決定する値を取得します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| LogicalChildren |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 Element) |
| Margin |
ビューの余白を取得または設定します。 (継承元 View) |
| MinimumHeightRequest |
レイアウト時に要素によって要求される高さの最小値をオーバーライドする値を取得または設定します。 (継承元 VisualElement) |
| MinimumWidthRequest |
レイアウト時に要素によって要求される最小幅をオーバーライドする値を取得または設定します。 (継承元 VisualElement) |
| Navigation | (継承元 NavigableElement) |
| NavigationProxy | (継承元 NavigableElement) |
| Opacity |
描画時に要素に適用する不透明度値を取得または設定します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| Padding |
ボタンの埋め込みを取得または設定します。 |
| Parent |
要素の親要素を取得または設定します。 (継承元 Element) |
| ParentView |
互換性のために残されています。
この要素の最も近い祖先 (すなわち VisualElement) である要素を取得します。 (継承元 Element) |
| Platform |
互換性のために残されています。
(継承元 Element)
|
| RealParent |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 Element) |
| Resources |
ローカルのリソース ディクショナリを取得または設定します。 (継承元 VisualElement) |
| Rotation |
要素の描画時に、Z 軸を中心とする回転 (アフィン回転) (度単位) を取得または設定します。 (継承元 VisualElement) |
| RotationX |
要素の描画時に、X 軸を中心とする回転 (パースペクティブ回転) (度単位) を取得または設定します。 (継承元 VisualElement) |
| RotationY |
要素の描画時に、Y 軸を中心とする回転 (パースペクティブ回転) (度単位) を取得または設定します。 (継承元 VisualElement) |
| Scale |
要素に適用するスケール ファクターを取得または設定します。 (継承元 VisualElement) |
| ScaleX |
X 方向に適用するスケールの値を取得または設定します。 (継承元 VisualElement) |
| ScaleY |
Y 方向に適用するスケールの値を取得または設定します。 (継承元 VisualElement) |
| Style | (継承元 NavigableElement) |
| StyleClass | (継承元 NavigableElement) |
| StyleId |
要素を一意に識別するユーザー定義の値を取得または設定します。 (継承元 Element) |
| TabIndex | (継承元 VisualElement) |
| Text |
ボタンのコンテンツとして表示されるテキストを取得または設定します。 これはバインド可能なプロパティです。 |
| TextColor |
ボタンのテキストの Color を取得または設定します。 これはバインド可能なプロパティです。 |
| TextTransform | |
| TranslationX |
要素の X 変換差分を取得または設定します。 (継承元 VisualElement) |
| TranslationY |
要素の Y 変換差分を取得または設定します。 (継承元 VisualElement) |
| Triggers |
この要素に関連付けられているトリガーの一覧を取得します。 これはバインド可能なプロパティです。 (継承元 VisualElement) |
| VerticalOptions |
レイアウト サイクルで要素がどのように配置されるかを定義する LayoutOptions を取得または設定します。 これはバインド可能なプロパティです。 (継承元 View) |
| Visual | (継承元 VisualElement) |
| Width |
この要素の描画時の現在の幅を取得します。 これはバインド可能な読み取り専用プロパティです。 (継承元 VisualElement) |
| WidthRequest |
この要素の必要な幅オーバーライドを取得または設定します。 (継承元 VisualElement) |
| X |
この要素の現在の X 位置を取得します。 これはバインド可能な読み取り専用プロパティです。 (継承元 VisualElement) |
| Y |
この要素の現在の Y 位置を取得します。 これはバインド可能な読み取り専用プロパティです。 (継承元 VisualElement) |
メソッド
イベント
| BatchCommitted |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| BindingContextChanged |
BindingContext プロパティが変更されるたびに発生します。 (継承元 BindableObject) |
| ChildAdded |
子要素が要素に追加されるたびに発生します。 (継承元 Element) |
| ChildRemoved |
子要素が要素から削除されるたびに発生します。 (継承元 Element) |
| ChildrenReordered |
VisualElement の子の順序が変更されると発生します。 (継承元 VisualElement) |
| Clicked |
ボタンがクリックされたときに発生します。 |
| DescendantAdded |
子要素が要素サブツリーに追加されるたびに発生します。 (継承元 Element) |
| DescendantRemoved |
子要素が要素サブツリーから削除されるたびに発生します。 (継承元 Element) |
| FocusChangeRequested |
Xamarin.Forms プラットフォームによる内部使用向け。 (継承元 VisualElement) |
| Focused |
要素がフォーカスを受け取ると発生します。 (継承元 VisualElement) |
| MeasureInvalidated |
ビジュアル要素のレイアウトが無効になったときに発生するイベント。 (継承元 VisualElement) |
| PlatformSet |
互換性のために残されています。
(継承元 Element)
|
| Pressed |
ボタンが押されたときに発生します。 |
| PropertyChanged |
プロパティが変更されたときに発生します。 (継承元 BindableObject) |
| PropertyChanging |
プロパティが変更されようとしているときに発生します。 (継承元 BindableObject) |
| Released |
ボタンが放されたときに発生します。 |
| SizeChanged |
この要素の Width プロパティまたは Height プロパティの値が変更されると発生します。 (継承元 VisualElement) |
| Unfocused |
要素がフォーカスを失ったときに発生します。 (継承元 VisualElement) |