WPF -Befehl CaneExecute wird mit dem Befehlsparameter in DataTemplate nicht aufgerufenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 WPF -Befehl CaneExecute wird mit dem Befehlsparameter in DataTemplate nicht aufgerufen

Post by Anonymous »

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)
{
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post