开发者

Adding a Behavior in a Resource Dictionary

I'm using Mark Smith's Julmar MVVM-Helpers library in an application and would like to add one of his behavior's to all my textboxs. Obviously, this needs to be done in a Resource dictionary, but I'm very much still a newbie at configuring them.

What I want to do is to add the below behavior

namespace JulMar.Windows.Interactivity
{
   /// <summary>
   /// This behavior selects all text in a TextBox when it gets focus
   /// </summary>
   public class SelectTextOnFocusBehavior : 开发者_运维知识库Behavior<TextBox>
   {....

To all of my textboxes. What I cannot find is the syntax on how to add this in the resource dictionary.


Assuming the SelectTextOnFocusBehavior class is used in a XAML file in the same assembly, then you'd want to do something like:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜