全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株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
XAML を使用して `RelayCommand` を呼び出す際に自身の `Window` を渡す方法は、コマンドパラメーターを使用することです。以下に、XAML のサンプルコードを示します。 ```xml <Window x:Class="ICommandSample.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:ICommandSample" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <Button Content="Execute Command" Command="{Binding MyCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" /> </Grid> </Window> ``` この XAML の例では、`Button` に `Command` プロパティに `MyCommand` をバインディングし、`CommandParameter` に `Binding` を使って `Window` インスタンスを渡しています。`RelativeSource` を使用して、親要素である `Window` を探し、そのインスタンスを `CommandParameter` として渡しています。 これにより、`RelayCommand` のコンストラクターで渡されたパラメーターとして、自身の `Window` を取得できます。そして、その `Window` を使用して必要な処理を行うことができます。 お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.03.13 04:37:23
[C#.NET] カテゴリの最新記事
|