代码之家  ›  专栏  ›  技术社区  ›  photo_tom

在资源字典中添加行为

  •  2
  • photo_tom  · 技术社区  · 15 年前

    我正在一个应用程序中使用MarkSmith的julmar mvvm helpers库,并希望将他的行为之一添加到我的所有文本框中。显然,这需要在资源字典中完成,但我仍然是配置它们的新手。

    我要做的是添加以下行为

    namespace JulMar.Windows.Interactivity
    {
       /// <summary>
       /// This behavior selects all text in a TextBox when it gets focus
       /// </summary>
       public class SelectTextOnFocusBehavior : Behavior<TextBox>
       {....
    

    所有的文本框。我找不到的是如何在资源字典中添加这个的语法。

    1 回复  |  直到 15 年前
        1
  •  1
  •   CodeNaked    15 年前

    假设在同一程序集中的XAML文件中使用了SelectTextOnFocusBehavior类,则需要执行以下操作:

    <Application x:Class="MyApplication.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:JulMar.Windows.Interactivity"
             StartupUri="MainWindow.xaml">
        <Application.Resources>
    
            <Style TargetType="TextBox">
                <Setter Property="local:SelectTextOnFocusBehavior.YourProperty" Value="YourValue" />
            </Style>
    
        </Application.Resources>
    </Application>
    
    推荐文章