2

我有以下用户控件:

<UserControl x:Class="DueVCheck.Pl.Gui.CustomControl.ListInfoBar"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:DueVCheck.Pl.Gui.CustomControl"
         mc:Ignorable="d" d:DataContext="{d:DesignInstance local:ListInfoBar}" >      
    <Button Name="NewRowBtn" Margin="5" Click="NewRowBtn_OnClick" Content="New"/>
</UserControl>   

代码隐藏文件:

using System.Windows;

namespace DueVCheck.Pl.Gui.CustomControl
{
    public partial class ListInfoBar
    {       
        public ListInfoBar()
        {
            DataContext = this;
            InitializeComponent();
        }

        public static readonly RoutedEvent NewClickEvent =
        EventManager.RegisterRoutedEvent("NewClick", RoutingStrategy.Bubble,
            typeof(RoutedEventHandler), typeof(ListInfoBar));

        public event RoutedEventHandler NewClick
        {
            add { AddHandler(NewClickEvent, value); }
            remove { RemoveHandler(NewClickEvent, value); }
        }

        private void NewRowBtn_OnClick(object sender, RoutedEventArgs e) 
        { 
            RaiseEvent(new RoutedEventArgs(NewClickEvent)); }
        }
    }
}

用户控件的用法:

<customControl:ListInfoBar Margin="10,0,10,0" NewClick="NewRowOnClick"/>

我需要的是用户NewRowBtn控件在 NewClick 未通过 XAML 绑定时禁用。问题是在通过 XAML 绑定事件时从未调用添加或删除。如何解决这个问题?

4

0 回答 0