我想创建一个继承 WPF 网格 并具有以下功能的 自定义控件:
- 它必须有一些默认行
- 它必须有一些子控件
这些行(主要是按钮和线条)
默认
- 非默认内容
必须可由设计师编辑或
在插入控件的窗口的 xaml 中写入内容
我尝试继承 Grid 并在构造函数中添加内容,但是一旦设计器添加更多内容,默认内容就会丢失。我尝试了很多事情,但我没能成功。有可能吗?我怎样才能做到这一点?
I want to create a Custom Control that inherits WPF Grid with these features:
- It must have some rows by default
- It must have some child controls in
those rows (mainly buttons and lines)
by default
- The non default content
must be editable by designer or
writting content in xaml of the window where the control is inserted
I tried inheriting Grid and adding content in the constructor but as soon as I add more content by designer, default content is lost. I have tried lots of things but I couldn't manage to make it. Is it even possible? How could I make this?
发布评论
评论(1)
马丁,你不能这么做。
网格是一种面板,其内容作为子属性。因此,如果您在 XAML 设计器中向其中添加任何内容,它将被替换。
但是,您可以覆盖子属性,并将其添加到您的类
中,如示例所示 - 例如:
Martin, You can't do that.
Grid is a type of panel, with content as children property. So, if you add anything to it in XAML designer it will be relpaced.
However you can override childern property, and add this to your class
<ContentProperty("PropertyName")>
like in the example -Ex: