复制自定义控件的 WPF TabControl 选定 TabItem 设计时行为
我正在开发一个显示内联弹出窗口的自定义控件,我想使用与 TabControl 采用的类似技术,以便仅在设计器中选择弹出窗口,或者更常见的是通过将光标放置在 XAML 中的弹出窗口声明中来选择弹出窗口它可以在设计器中直接可视化,而无需运行应用程序或手动更改任何运行时值。
我首先复制 TabControl 的实现,我已经成功地模仿了所有内容,但它都是从 Reflector 输出和 Stylesnooper 复制的。我重命名了所有控件部分,然后替换了默认模板,以便主控件使用 ItemsPresenter 而不是 ContentPresenter 来显示网格面板中相互叠加的各个弹出控件。到目前为止,这也效果很好。问题在于,我失去了让设计器遵循 XAML 编辑器中选择的项目的能力。
要么解释 TabControl 的设计时行为功能实际上如何工作来描述我上面描述的所选 TabItem 行为,要么只是提供一些关于如何实现我想要做的事情的指示,这都很好。
I'm developing a custom control which shows an inline popup window and I would like to use a similar technique as the TabControl employes so that only popup windows that are selected within the designer or more commonly by placing the cursor within the popup declaration in XAML that it is visualized right within the desiger without having to run the application or change any runtime values by hand.
I've started by duplicating the implementation of the TabControl which I have successfully mimicking everything but it is all copied from Reflector output and Stylesnooper. I've renamed all of the control parts and then replaced the default templates so that the main control uses an ItemsPresenter instead of a ContentPresenter to show the individual popup controls within a Grid panel overlayed on top of one another. So far this is working great too. The problem is that somewhere along the line I lost the ability to have the designer follow the item that is selected in the XAML editor.
Either an explanation of how the TabControl's design time behavior functionality actually works to describe the selected TabItem behavior that I described above or just some pointers on how one could achieve what I'm tryign to do would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决类似的问题,我必须为自定义选项卡控件创建设计时支持。以下是WPF 设计器扩展性。
基本上,我创建了一个 PrimarySelectionAdornerProvider 来处理点击交互,并创建了一个 FeatureConnector<> 。 /FeatureProvider 对用于选择更改(包括在 xaml 编辑器中进行的选择更改)。
功能提供程序/连接器:
编辑(更多信息):
此 Microsoft 链接 有许多指向演练的链接,应该会有所帮助。以下是入门的基本步骤:
创建一个新项目 MyAssembly.VisualStudio.Design.dll。
该库应编译到与 MyAssembly.dll 相同的位置(重要)。
添加对 Microsoft.Windows.Design.Extensibility 和 Microsoft.Windows.Design.Interaction 的引用。
添加对您的控件库的引用。
创建一个名为元数据的类
代码:
创建一个类来自 PrimarySelectionAdornerProvider(重命名为您想要的任何名称)。请参阅链接以获得详细的演练。
根据上面的示例创建 AutoTabPageSelectionFeatureProvider 和 AutoTabPageSelectionFeatureConnector。
To solve a similar problem, I had to create design time support for my custom tab control. Here is a link for WPF Designer Extensibility.
Basically, I created a PrimarySelectionAdornerProvider to handle click interaction and a FeatureConnector<> / FeatureProvider pair for selection changes (including selection changes made in the xaml editor).
The feature provider / connector:
Edit (more info):
This Microsoft link has a number of links to walk-throughs that should help. Here are the basic steps to get started:
Create a new project, MyAssembly.VisualStudio.Design.dll.
The library should compile to the same location as MyAssembly.dll (important).
Add references to Microsoft.Windows.Design.Extensibility and Microsoft.Windows.Design.Interaction.
Add a reference to your control library.
Create a class called Metadata
Code:
Create a class MyPrimaryAdornerProvider from PrimarySelectionAdornerProvider (rename to whatever you want). See link for good walk-through.
Create the AutoTabPageSelectionFeatureProvider and AutoTabPageSelectionFeatureConnector from the example above.