4

私はこの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>

このコード ビハインド (削除されたusings):

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");
        }
    }
}

デバッガーとコンソールのログの両方で、起動することはないようです。奇妙なことは、出力にエラーが記録されないため、バインディングが問題ないように見えることです。意図的にバインドを解除すると、バインド エラーが発生しますが、上記のバインドではエラーは発生しませんが、起動することはありません。

4

1 に答える 1

9

CreateCommand = new DelegateCommand(Create);前に置いてみるInitializeComponent();

于 2012-05-26T16:04:54.907 に答える