c# - 在行为中使用静态资源

标签 c# wpf

我有一个文本框并添加了一个行为:

<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>

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

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

最佳答案

Interaction.Behaviors是只读的 BehaviorCollection继承自 AttachableCollection<Behavior> & 你不能在其上设置绑定(bind)。

关于c# - 在行为中使用静态资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391966/

相关文章:

c# - 想要在运行时在程序集内加载程序集?

c# - 如何从 RGB 颜色创建 WPF 图像?

c# - 动态格式化的 TextBlock

c# - asp.net 中的 ajax 加载器

c# - 在不使用任何外部文件的情况下使用 C# 列出回收站中的文件名

c# - Wpf ItemSsource 不更新自定义控件中的视觉控件

c# - WPF 的自动完成组合框

c# 在 RelayCommand 中缺少 TapHandler

c# - Ajax.BeginForm 替换整个页面

c# - 如何将 List<Class> 转换为 String?