全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株Stock
| VBA
| SharePoint
| REST API
| RenderListDataAsStream
| PowerAutomateDesktop
| Graph API
| PowerApps
| PowerAutomate
| PowerFx
| OfficeScriptオフィススクリプト
| PowerAutomate日時Excel日時相互関係
| PowerShell
| Dataverse
| UiPath
| OneDrive
| LINQ
| VB.NET
| C#.NET
| WPFC#.NET
| Git
カテゴリ:C#.NET
WPFのWindow.Resourcesでよく利用されるリソースには、次のようなものがあります。 1. スタイル(Style): スタイルは、UI要素の外観や動作を定義するのに使用されます。たとえば、ボタンのスタイルを定義して再利用することができます。 ```xml <Window.Resources> <Style x:Key="ButtonStyle" TargetType="Button"> <Setter Property="Background" Value="Blue"/> <Setter Property="Foreground" Value="White"/> <Setter Property="FontSize" Value="14"/> </Style> </Window.Resources> ``` 2. テンプレート(ControlTemplate): テンプレートは、UI要素のレイアウトを定義します。たとえば、ボタンのテンプレートを定義してカスタムの外観を適用することができます。 ```xml <Window.Resources> <ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> <Border Background="LightGray" BorderBrush="Black" BorderThickness="1"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Window.Resources> ``` 3. データバインディングのコンバーター(Converter): コンバーターは、データバインディングの値を変換するのに使用されます。たとえば、日付を和暦に変換するコンバーターを定義することができます。 ```xml <Window.Resources> <local:JapaneseCalendarConverter x:Key="JapaneseCalendarConverter"/> </Window.Resources> ``` 4. データバインディングのスタイル(DataTemplate): データバインディングのスタイルは、データ型ごとに異なる外観を定義するのに使用されます。たとえば、リストボックスのアイテムの外観をカスタマイズするために使用されます。 ```xml <Window.Resources> <DataTemplate DataType="{x:Type local:Person}"> <StackPanel> <TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding Age}"/> </StackPanel> </DataTemplate> </Window.Resources> ``` これらのリソースは、WindowやUserControlなどの親要素のResourcesセクションで定義され、その要素内のすべての子要素で利用可能です。リソースを使うことで、コードを効率化し、外観や動作を再利用可能にすることができます。 お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.04.21 15:23:59
[C#.NET] カテゴリの最新記事
|