gpt4 book ai didi

caliburn.micro - Caliburn 微 : How to add text to the bottom of a list box and display it

转载 作者:行者123 更新时间:2023-12-04 06:37:14 27 4
gpt4 key购买 nike

我想弄清楚如何将文本添加到列表框的底部并显示它。在带有代码的 WPF 中,我会捕获 ScrollViewer 并对其进行操作,但我无法弄清楚如何使用 Caliburn 来做到这一点...

最佳答案

您有几个选择。

1) 在您的 ViewModel 中,您可以调用 GetView 并将其转换为您的 View 类型并获取对 ScrollViewer 的引用。像这样的东西:

var myView = this.GetView() as MyView;
var myScrollView = myView.MyScrollView;

这很好用,但如果您不想将 View 耦合到 View 模型,则效果不理想。

选项 2) 是实现 IResult,请参阅文档 here .

public class ScrollViewResult : IResult
{
public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };

private ScrollViewResult ()
{
}

public void Execute (ActionExecutionContext context)
{
var view = context.View as FrameworkElement;
var scrollViewer = FindVisualChild<ScrollViewer>(view);

//do stuff to scrollViewer here

Completed (this, new ResultCompletionEventArgs { });
}

private static TChildItem FindVisualChild<TChildItem> (DependencyObject obj)
where TChildItem : DependencyObject
{
for (var i = 0; i < VisualTreeHelper.GetChildrenCount (obj); i++)
{
var child = VisualTreeHelper.GetChild (obj, i);
if (child != null && child is TChildItem)
return (TChildItem)child;

var childOfChild = FindVisualChild<TChildItem> (child);
if (childOfChild != null)
return childOfChild;
}
return null;
}

//this isn't required of course but comes in handy for
//having a static method and passing parameters to the
//ctor of the IResult
public static IResult DoSomething ()
{
return new ScrollViewResult ();
}

然后你可以这样调用它:

public IEnumerable<IResult> SomeAction()
{
yield return ScrollViewResult.DoSomething();
}

关于caliburn.micro - Caliburn 微 : How to add text to the bottom of a list box and display it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13223371/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com