C# 将枚举值绑定到XAML中的附加属性

C# 将枚举值绑定到XAML中的附加属性,c#,wpf,xaml,enums,attached-properties,C#,Wpf,Xaml,Enums,Attached Properties,我有下面的类,它有一个枚举和一个附加属性 namespace U.Helpers { public enum SearchDirection { Forward, Backward } public class TargetedTriggerActionFindNextButton : TargetedTriggerAction<DataGrid> { protected override voi

我有下面的类,它有一个枚举和一个附加属性

namespace U.Helpers
{
    public enum SearchDirection
    {
        Forward,
        Backward
    }
    public class TargetedTriggerActionFindNextButton : TargetedTriggerAction<DataGrid>
    {
        protected override void Invoke(object parameter)
        {
            if (SearchDirectionControl == SearchDirection.Forward)
                //Do something
            else
                //Do something else
            }

        public static readonly DependencyProperty SearchDirectionControlProperty =
            DependencyProperty.Register("SearchDirectionControl", typeof(object), typeof(TargetedTriggerActionFindNextButton), new PropertyMetadata(SearchDirection.Forward));

        public SearchDirection SearchDirectionControl
        {
            get { return (SearchDirection)GetValue(SearchDirectionControlProperty); }
            set { SetValue(SearchDirectionControlProperty, value); }
        }
    }
}
名称空间U.助手
{
公共枚举搜索方向
{
向前地
向后的
}
公共类TargetedTriggerAction FindNext按钮:TargetedTriggerAction
{
受保护的覆盖无效调用(对象参数)
{
if(SearchDirectionControl==SearchDirection.Forward)
//做点什么
其他的
//做点别的
}
公共静态只读从属属性SearchDirectionControlProperty=
DependencyProperty.Register(“SearchDirectionControl”、typeof(object)、typeof(TargetedTriggerActionFindNext按钮)、new PropertyMetadata(SearchDirection.Forward));
公共搜索方向搜索方向控制
{
获取{return(SearchDirection)GetValue(SearchDirectionControlProperty);}
set{SetValue(SearchDirectionControlProperty,value);}
}
}
}
以下是我目前的XAML:

<UserControl x:Class="UM.LaunchPad"
             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:helpers="clr-namespace:UM.Helpers">

    <Grid Name="gridUsers" Background="Transparent">
        <Button Name="SearchNextButton" Content="Next" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <helpers:TargetedTriggerActionFindNextButton TargetObject="{Binding ElementName=GenericDataGrid}" 
                             SearchDirectionControl="{Binding helpers:SearchDirection.Forward}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </Grid>
</UserControl>


我想知道如何将枚举值添加到XAML端的附加属性中。请参见按钮的SearchDirectionControl

如果要引用特定的枚举值,请不要使用绑定,而是使用:

<helpers:TargetedTriggerActionFindNextButton
    TargetObject="{Binding ElementName=GenericDataGrid}" 
    SearchDirectionControl="{x:Static helpers:SearchDirection.Forward}"
/>
A constant
A static property
A field   [sic; it should be a "static field", obviously]
An enumeration value