RelayCommand<T> does not work with Enumerations
まだ誰も着手していません。
評価
調査の方向性
提供された UWP の再現コードをもとに、まず RelayCommand と生成された SetSortOrderCommand を追跡します。SortOrder enum と uint ベースの CommandParameter で失敗を再現し、その後、enum パラメーターが CanExecute と実行に正しく渡ることを確認します。報告された binding シナリオが uint と SortOrder の不一致なしに動作すれば、Issue は完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
If you try to bind an enum to a CommandParameter in UWP, then UWP tends to pass them around the system as the raw type of the enum as opposed to the .net type.
This means that when you bind to it and it fires the CanExecute(object?), that it fails because the type does not match (uint != SortOrder)
Regression
No response
Steps to reproduce
I've provided a bare-bones reproduction here:
https://github.com/[AtomicBlom/EnumRelayCommandTest](https://github.com/AtomicBlom/EnumRelayCommandTest)
But if you create a blank app, and add a ViewModel based on ObservableObject, something like this:
public partial class MainPageViewModel : ObservableObject
{
[RelayCommand]
private void OnSetSortOrder(SortOrder order)
{
Debug.WriteLine($"Sort order set to {order}");
}
}
public enum SortOrder : uint
{
Ascending,
Descending
}
Then attempt to bind to it.
<Button Command="{x:Bind ViewModel.SetSortOrderCommand, Mode=OneWay}" Content="Press me">
<Button.CommandParameter>
<local:SortOrder>Ascending</local:SortOrder>
</Button.CommandParameter>
</Button>
You'll find that it fails
Expected behavior
You should be able to pass an enum as a CommandParameter
Screenshots
No response
IDE and version
VS 2022
IDE version
17.12.4
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.0
Additional context
This error was also observed while attempting to port a UWP application to .net9
Help us help you
Yes, I'd like to be assigned to work on this item
- 主要言語
- C#
- スター
- 3.8k
- フォーク
- 402
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
CommunityToolkit/dotnet のほかの issue
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicate対応中かも @apachezy が 121 日前に担当しました。 オープンbug :bug:
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
CommunityToolkit/dotnet#1206 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
CommunityToolkit/dotnet#648 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
CommunityToolkit/dotnet#1218 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
CommunityToolkit/dotnet#1217 ·
CommunityToolkit/dotnet の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 2 日以内に返信
-
area: core bug help wanted ready
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ZaidX88/sluice#265 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
area: remote bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
CodeYourFuture/Module-Tools#712 ·