13,005
回編集
(→属性) |
(→プロパティ) |
||
369行目: | 369行目: | ||
== プロパティ == | == プロパティ == | ||
Buttonコントロールには多くのプロパティが存在する。<br> | Buttonコントロールには多くのプロパティが存在する。<br> | ||
<br> | |||
ボタンコントロールのプロパティを使用することにより、C#のコードからAvalonia UIのボタンの外観や動作を動的に操作することができる。<br> | |||
例えば、ユーザのアクションやアプリケーションの状態に応じてボタンの外観や機能を変更することができる。<br> | |||
<br> | <br> | ||
視覚的な要素から機能的な面まで、幅広い調整が可能である。<br> | 視覚的な要素から機能的な面まで、幅広い調整が可能である。<br> | ||
375行目: | 377行目: | ||
これらは頻繁に使用され、ボタンの基本的な外観と機能を定義するのに役立つ。<br> | これらは頻繁に使用され、ボタンの基本的な外観と機能を定義するのに役立つ。<br> | ||
<br> | <br> | ||
<center> | |||
{| class="wikitable" style="background-color:#fefefe;" | |||
|+ Buttonコントロールのプロパティ | |||
|- | |||
! style="background-color:#00ffff;" | プロパティ名 | |||
! style="background-color:#00ffff;" | データ型 | |||
! style="background-color:#00ffff;" | 説明 | |||
|- | |||
| Content || object || ボタン内に表示されるコンテンツを取得または設定する。<br><br>例: <code>myButton.Content = "Click Me";</code> | |||
|- | |||
| Command || ICommand || ボタンが押下された時に実行されるコマンドを取得または設定する。<br>ボタンが押下された時、呼び出される<code>ICommand</code>インターフェースのインスタンス。<br><br>例: <code>myButton.Command = new RelayCommand(ExecuteMethod);</code> | |||
|- | |||
| CommandParameter || object || コマンドに渡されるパラメータを取得または設定する。<br><br>例: <code>myButton.CommandParameter = someObject;</code> | |||
|- | |||
| IsDefault || bool || ボタンがデフォルトボタンであるかどうかを示す値を取得または設定する。<br><br>例: <code>myButton.IsDefault = true;</code> | |||
|- | |||
| IsCancel || bool || ボタンがキャンセルボタンであるかどうかを示す値を取得または設定する。<br><br>例: <code>myButton.IsCancel = true;</code> | |||
|- | |||
| ClickMode || ClickMode || ボタンが押下されたと見なされるタイミングを取得または設定する。<br>(ボタンが押下された時、どのように反応するかを記述する。)<br><br>例: <code>myButton.ClickMode = ClickMode.Press;</code> | |||
|- | |||
| IsPressed || bool || ボタンが現在押されているかどうかを示す値を取得する。<br>(読み取り専用)<br><br>例: <code>bool isPressed = myButton.IsPressed;</code> | |||
|- | |||
| Background || IBrush || ボタンの背景を取得または設定する。<br><br>例: <code>myButton.Background = Brushes.Blue;</code> | |||
|- | |||
| Foreground || IBrush || ボタンの前景 (主にテキスト) の色を取得または設定する。<br><br>例: <code>myButton.Foreground = Brushes.White;</code> | |||
|- | |||
| BorderBrush || IBrush || ボタンの境界線の色を取得または設定する。<br><br>例: <code>myButton.BorderBrush = Brushes.Black;</code> | |||
|- | |||
| BorderThickness || Thickness || ボタンの境界線の太さを取得または設定する。<br><br>例: <code>myButton.BorderThickness = new Thickness(2);</code> | |||
|- | |||
| CornerRadius || CornerRadius || ボタンの角の丸みを取得または設定する。<br><br>例: <code>myButton.CornerRadius = new CornerRadius(5);</code> | |||
|- | |||
| Padding || Thickness || ボタンの内部余白を取得または設定する。<br><br>例: <code>myButton.Padding = new Thickness(5, 10);</code> | |||
|- | |||
| HorizontalContentAlignment || HorizontalAlignment || ボタン内のコンテンツの水平方向の配置を取得または設定する。<br><br>例: <code>myButton.HorizontalContentAlignment = HorizontalAlignment.Center;</code> | |||
|- | |||
| VerticalContentAlignment || VerticalAlignment || ボタン内のコンテンツの垂直方向の配置を取得または設定する。<br><br>例: <code>myButton.VerticalContentAlignment = VerticalAlignment.Center;</code> | |||
|- | |||
| FontFamily || FontFamily || ボタンのテキストのフォントファミリーを取得または設定する。<br><br>例: <code>myButton.FontFamily = new FontFamily("Arial");</code> | |||
|- | |||
| FontSize || double || ボタンのテキストのフォントサイズを取得または設定する。<br><br>例: <code>myButton.FontSize = 16;</code> | |||
|- | |||
| FontWeight || FontWeight || ボタンのテキストのフォントの太さを取得または設定する。<br><br>例: <code>myButton.FontWeight = FontWeight.Bold;</code> | |||
|- | |||
| IsEnabled || bool || ボタンが有効かどうかを示す値を取得または設定する。<br><br>例: <code>myButton.IsEnabled = false;</code> | |||
|- | |||
| Opacity || double || ボタンの不透明度を取得または設定する。<br><br>例: <code>myButton.Opacity = 0.5;</code> | |||
|- | |||
| Tag || object || ボタンに関連付けられた任意のデータを取得または設定する。<br><br>例: <code>myButton.Tag = someObject;</code> | |||
|} | |||
</center> | |||
<br> | |||
==== 使用例 ==== | |||
以下の例では、ボタンの外観を初期化して、クリックイベントを設定している。<br> | |||
ボタンが押下された時、そのコンテンツが変更されて無効化している。<br> | |||
<br> | <br> | ||
<syntaxhighlight lang="c#"> | |||
public class MainWindow : Window | |||
{ | |||
private Button myButton; | |||
public MainWindow() | |||
{ | |||
InitializeComponent(); | |||
myButton = this.FindControl<Button>("MyButton"); | |||
// ボタンのプロパティを設定 | |||
myButton.Content = "Click Me"; | |||
myButton.Background = Brushes.Blue; | |||
myButton.Foreground = Brushes.White; | |||
myButton.FontSize = 16; | |||
myButton.Padding = new Thickness(10); | |||
myButton.CornerRadius = new CornerRadius(5); | |||
// クリックイベントを設定 | |||
myButton.Click += MyButton_Click; | |||
} | |||
private void MyButton_Click(object sender, RoutedEventArgs e) | |||
{ | |||
// ボタンがクリックされた時の処理 | |||
myButton.Content = "Clicked!"; | |||
myButton.IsEnabled = false; | |||
} | |||
} | |||
</syntaxhighlight> | |||
<br><br> | <br><br> | ||