我有一个textbox并添加了一个行为:

<TextBox VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Grid.Row="0" Grid.Column="1"
                 FontSize="22" >
            <Binding Path="IpAddr" ValidatesOnNotifyDataErrors="True">
                <Binding.ValidationRules>
                    <local:IpAddressRule />
                </Binding.ValidationRules>
            </Binding>
            <i:Interaction.Behaviors>
                <behaviors:TextBoxInputMaskBehavior InputMask="{StaticResource InputMaskIp}" PromptChar="0" />
            </i:Interaction.Behaviors>
        </TextBox>


现在,我已经在资源中移动了TextBoxInputMaskBehavior

<UserControl.Resources>
        <system:String x:Key="InputMaskIp">000.000.000.000</system:String>
        <behaviors:TextBoxInputMaskBehavior x:Key="mask" InputMask="{StaticResource InputMaskIp}" PromptChar="0" />
    </UserControl.Resources>


现在我的问题是,如何将资源绑定到:

<i:Interaction.Behaviors>
    //Will bind resources here.
</i:Interaction.Behaviors>

最佳答案

Interaction.Behaviors是从BehaviorCollection继承的只读AttachableCollection<Behavior>,不能在其上设置绑定。

10-01 19:34