MochiuWiki : SUSE, EC, PCB
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
検索
個人用ツール
ログイン
Toggle dark mode
名前空間
ページ
議論
表示
閲覧
ソースを閲覧
履歴を表示
Avalonia UI - Buttonのソースを表示
提供: MochiuWiki : SUSE, EC, PCB
←
Avalonia UI - Button
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループのいずれかに属する利用者のみが実行できます:
管理者
、new-group。
このページのソースの閲覧やコピーができます。
== 概要 == <br><br> == カスタムコントロール == Avalonia UIにおいて、Buttonコントロールを拡張する場合は、カスタムコントロールを作成することが一般的なアプローチである。<br> これにより、標準のButtonコントロールの機能に加えて、独自のプロパティ、メソッド、イベントを追加することができる。<br> <br> 以下の例では、カスタムButtonクラス (ExtendedButtonクラス) にCustomBackgroundプロパティを追加して、それをテンプレートで使用している。<br> また、必要に応じて、他のプロパティおよびロジックを追加してカスタマイズを行うことができる。<br> <br> Avalonia UIでは、コントロールを拡張してソフトウェアのニーズに合わせたカスタマイズを行うことができる。<br> <br> ==== カスタムButtonクラスの作成 ==== まず、Buttonクラスを継承する新しいクラスを作成する。<br> このクラスでは、新しいプロパティ、メソッドを追加して、Buttonコントロールの機能を拡張する。<br> <syntaxhighlight lang="c#"> // ExtendedButton.cs using Avalonia; using Avalonia.Controls; using Avalonia.Media; namespace <任意の名前空間名> { public class <カスタムButtonのクラス名> : Button { public static readonly StyledProperty<Brush> CustomBackgroundProperty = AvaloniaProperty.Register<ExtendedButton, Brush>(nameof(CustomBackground)); public Brush CustomBackground { get => GetValue(CustomBackgroundProperty); set => SetValue(CustomBackgroundProperty, value); } // カスタムロジックやプロパティを追加 // ...略 } } </syntaxhighlight> <br> ==== スタイルとテンプレートの定義 ==== 次に、カスタムButtonクラスの外観を定義するため、スタイルとテンプレートを定義する。<br> これは、Avaloniaのリソース辞書ファイル (例えば、Themesフォルダ内のGeneric.xaml) で行うことができる。<br> <syntaxhighlight lang="xml"> <!-- ExtendedButton.xaml --> <Style xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:<任意の名前空間名>" TargetType="local:<カスタムButtonのクラス名>"> <Setter Property="Template"> <ControlTemplate TargetType="local:<カスタムButtonのクラス名>"> <Border Background="{TemplateBinding CustomBackground}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter> </Style> </syntaxhighlight> <br> ==== カスタムButtonクラスの使用 ==== 上記の手順により、カスタムButtonクラスをXAMLおよびコードビハインドで使用することができる。<br> <syntaxhighlight lang="xml"> <!-- MainWindow.axaml --> <Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:<任意の名前空間名>" x:Class="<アプリケーションの名前空間名>.MainWindow"> Title="<アプリケーションのタイトル>" Height="600" Width="1024"> <StackPanel> <local:<カスタムButtonのクラス名> CustomBackground="SkyBlue" Content="Custom Button" /> </StackPanel> </Window> </syntaxhighlight> <br><br> __FORCETOC__ [[カテゴリ:C_Sharp]]
Avalonia UI - Button
に戻る。
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
Collapse