是否可以在 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();
}
}
任何人都知道我该如何实现这一目标?