WPF -Befehl CaneExecute wird mit dem Befehlsparameter in DataTemplate nicht aufgerufen

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: WPF -Befehl CaneExecute wird mit dem Befehlsparameter in DataTemplate nicht aufgerufen

by Anonymous » 17 Aug 2025, 01:24

Aus irgendeinem Grund, obwohl ich zuerst commandParameter eingestellte, wird CaneExecute mit null .

Code: Select all

CommandParameter
-matters ding. Alle außer dem .NET7.0 eins.

Code: Select all


WinExe
net461;net481;net6.0-windows;net7.0-windows
enable
enable
preview
true


mainwindow.xaml

Code: Select all













mainwindow.xaml.cs

Code: Select all

using System.Diagnostics;
using System.Windows;
using System.Windows.Input;

namespace CommandParameterBug;

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}

public class ViewModel
{
public ICommand Cmd { get; }

public ViewModel()
{
Cmd = new TestCommand();
}
}

public class TestCommand : ICommand
{
public event EventHandler? CanExecuteChanged;

public bool CanExecute(object? parameter)
{
Debug.WriteLine($"CanExecute: {parameter}");
return parameter != null;
}

public void Execute(object? parameter)
{
}
}

Top