2010-11-27 114 views
2

我在應用程序中使用Mark Smith的Julmar MVVM-Helpers庫,並想將其行爲之一添加到所有文本框中。顯然,這需要在Resource字典中完成,但我仍然是配置它們的新手。在資源字典中添加行爲

我想要做的就是添加以下行爲

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

我所有的文本框的。我無法找到的是關於如何將其添加到資源字典中的語法。

回答

1

假設SelectTextOnFocusBehavior類在同一個組件中的XAML文件被使用,那麼你想要做的事,如:

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