Command derived from DependencyObject is not executing.
Posted: 28 Jan 2022, 15:08
As title says. If I remove DependencyObject from declaration, then command is executed.
In WPF this code runs as expected (command is executed).
Why do I need DependencyObject command? Because I'd prefer to use full featured binding, for some specific scenarios. Though, probably, I'll have to think of some workaround myself.
This post is mainly to highlight discrepancy in Noesis compared to WPF.
MainView.xaml:
Nothing special in MainView.xaml.cs, just the usual NoesisUnity.LoadComponent(this); and initialization of DataContext.
CommandProxy.cs:
In WPF this code runs as expected (command is executed).
Why do I need DependencyObject command? Because I'd prefer to use full featured binding, for some specific scenarios. Though, probably, I'll have to think of some workaround myself.
This post is mainly to highlight discrepancy in Noesis compared to WPF.
MainView.xaml:
Code: Select all
<UserControl x:Class="UI.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type={x:Type local:MainViewModel}, IsDesignTimeCreatable=False}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" >
<Button.Command>
<local:CommandProxy/>
</Button.Command>
Test button
</Button>
</Canvas>
</UserControl>
CommandProxy.cs:
Code: Select all
public class CommandProxy : ***DependencyObject***, ICommand
{
public bool CanExecute(object parameter) => true;
public void Execute(object parameter)
{
UnityEngine.Debug.Log("CommandProxy.Execute");
}
public event EventHandler CanExecuteChanged;
}