在WPF和Caliburn.Micro中,我是否可以控制我在视图中绑定的System.Windows.Interactivity.Behavior.Behavior的创建?
我的情况是,我想通过Caliburn.Micro Bootstrapper
向我的自定义行为注入依赖项,但我真的不想使用某种服务定位器。
我的视图如下:
<TextBox x:Name="Output">
<i:Interaction.Behaviors>
<core:ScrollBehavior />
</i:Interaction.Behaviors>
</TextBox>
这就是我想要实现的:
public class ScrollBehavior : Behavior<TextBox>
{
private readonly IMyExteneralDependency _externalDependency;
public ScrollBehavior(IMyExteneralDependency externalDependency)
{
_externalDependency = externalDependency;
}
protected override void OnAttached()
{
this.AssociatedObject.TextChanged += this.OnTextChanging;
}
protected override void OnDetaching()
{
this.AssociatedObject.TextChanged -= this.OnTextChanging;
}
private void OnTextChanging(object sender, TextChangedEventArgs e)
{
this.AssociatedObject.ScrollToEnd();
}
}
有人知道我如何实现这个吗?