私はこのXAMLを持っています:
<UserControl x:Class="Foo.UserControls.Bar"
x:Name="FooBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<WrapPanel Margin="4,0,0,0">
<Button Command="{Binding Path=CreateCommand, ElementName=FooBar}">
<TextBlock>Create</TextBlock>
</Button>
このコード ビハインド (削除されたusing
s):
namespace Foo.UserControls
{
public partial class Bar : UserControl
{
public DelegateCommand CreateCommand { get; private set; }
public Bar()
{
InitializeComponent();
CreateCommand = new DelegateCommand(Create);
}
private void Create(object action)
{
Console.WriteLine("foo");
}
}
}
デバッガーとコンソールのログの両方で、起動することはないようです。奇妙なことは、出力にエラーが記録されないため、バインディングが問題ないように見えることです。意図的にバインドを解除すると、バインド エラーが発生しますが、上記のバインドではエラーは発生しませんが、起動することはありません。