为什么这行不通?
在generic.xaml中用于自定义控件:
在应用于自定义控件的样式中...
<Setter Property="ChromeContent">
<Setter.Value>
<Grid />
</Setter.Value>
</Setter>
...
后来,在控制模板中...
<ContentPresenter Grid.Column="0"
x:Name="ChromeContentPresenter"
Content="{TemplateBinding ChromeContent}" />
这是 ChromeContent 的依赖属性...
public Object ChromeContent
{
get { return (Object)GetValue(ChromeContentProperty); }
set { SetValue(ChromeContentProperty, value); }
}
public static readonly DependencyProperty ChromeContentProperty =
DependencyProperty.Register("ChromeContent", typeof(Object),
typeof(casPopup), null);
如您所见,它需要任何对象。我尝试将其更改为网格,但这并没有帮助。
它抛出这个错误(来自javascript):_Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'
奇怪的是,如果我从设置器中删除 Grid 并且只使用文本,则以下内容将正常工作:
<Setter Property="ChromeContent" Value="DEFAULT" />
此外,这也适用于控件类中的 OnApplyTemplate 方法:
Grid g = new Grid();
g.Width = 100;
g.Height = 25;
g.Background = new SolidColorBrush(Colors.LightGray);
ChromeContent = g;
我很难理解是什么阻止了在 generic.xaml 中定义的网格的默认内容工作。有人对这件事有任何了解吗?
非常感谢您的帮助!