设置选择容器示例

发布于 2024-12-20 21:36:01 字数 539 浏览 4 评论 0 原文

我正在寻找一个使用 c# 调用 EnvDTE.Window 类上的 SetSelectionContainer 方法的简单示例。

我想知道我应该传递给该方法的类应该是什么样子。

我已经在网上搜索了好几天了,甚至找不到任何有帮助的东西。

Window window = _applicationObject.ItemOperations.NewFile(@"General\XML File", "", "");
TextSelection selection = (TextSelection) window.Document.Selection;
selection.SelectAll();
selection.Insert("<xml>some xml<xml>", (int)vsInsertFlags.vsInsertFlagsContainNewText);

object[] container = new[] {"Test1", "Test2"};
window.SetSelectionContainer(ref container);

I looking for a simple example using c# to call the SetSelectionContainer method on the EnvDTE.Window class.

I would like to know what the classes should look like that I should pass to the method.

I have really searched the web now for days and could not even find anything remotely helpful.

Window window = _applicationObject.ItemOperations.NewFile(@"General\XML File", "", "");
TextSelection selection = (TextSelection) window.Document.Selection;
selection.SelectAll();
selection.Insert("<xml>some xml<xml>", (int)vsInsertFlags.vsInsertFlagsContainNewText);

object[] container = new[] {"Test1", "Test2"};
window.SetSelectionContainer(ref container);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

客…行舟 2024-12-27 21:36:01

Sets the objects that should be passed to the Properties window
whenever the window has focus. SetSelectionContainer works only on
windows created with the CreateToolWindow method
. Other tool windows,
such as Solution Explorer and Task List, already have code for setting
what is displayed in the Properties window.

SetSelectionContainer
allows you to associate objects with the window so that whenever the
window has focus, the Properties window displays properties for those
objects. For example, you would use this property if you have a custom
tool window that displays a chart and you want to display properties
in the Properties window in order to change characteristics of the
chart.

If SetSelectionContainer is passed an empty Variant value, it
removes the displayed object. The object displays when the tool window
is active and the objects are available from the selection container.

Ref.

Have you downloaded the samples from here?: Automation and Extensibility for Visual Studio

听,心雨的声音 2024-12-27 21:36:01

根据我的发现,您可以传递简单的属性,例如此方法的对象数组参数中的字符串和整数。

看来实现这项工作的真正技巧是生成通知(通过 ITrackSelection.OnSelectChange) 属性已更改。

这里有一些工作代码

From what I have discovered, you can pass simple properties, such as strings and ints in the object array parameters for this method.

It appears that the real trick to making this work is generating the notification (through ITrackSelection.OnSelectChange) that the properties have changed.

There is some working code for this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文