1

我通过以下标准过程检索 MenuItem 的 ControlTemplate:

var resource = FindResource(new ComponentResourceKey(typeof(MenuItem), "TopLevelHeaderTemplateKey"));
var settings = new XmlWriterSettings() { Indent = true };
var sb = new StringBuilder();
var writer = XmlWriter.Create(sb, settings);
XamlWriter.Save(resource, writer);
MyTextBox.Text = sb.ToString();

我想知道,为什么我总是在 ControlTemplate 的深处得到:

<Popup IsOpen="False" ...

当工作版本是:

<Popup IsOpen="{TemplateBinding IsSubmenuOpen}" ...

通过 Reflector ILSpy 找不到任何硬编码问题。那么为什么标准版本的 MenuItem 正在工作呢?有人可以解释一下吗?

4

1 回答 1

1

I haven't checked it but perhaps it's because you're retrieving template at the run time. Data binding has already been applied to it.

I suggest using Expression Blend to get to the templates of your controls in design time. You'll have all the bindings that are defined there. Just right click on the control and find option like 'Template -> Edit Current'.

于 2012-05-22T07:36:49.910 回答