为什么这不起作用?
In 通用.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 allocate to property 'System.Windows.Controls.ContentPresenter.Content'
奇怪的是,如果我从设置器中删除网格并仅使用文本,则以下内容将正常工作:
<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 中定义的网格的默认内容工作。有人对此事有了解吗?
非常感谢您的帮助!