我该怎么办?
<Style TargetType="Grid">
<Setter Property="Children">
<Setter.Value>
...
</Setter.Value>
</Setter>
</Style>
我知道儿童只读,这给了我“儿童可预期的可写财产”。
由于
答案 0 :(得分:3)
您不能,因为Panel.Children
不是DependencyProperty
。您几乎肯定希望将ItemsControl
与自定义ItemsPanel
一起使用。但是,如果没有更多信息,我无法确切地说出来。
答案 1 :(得分:1)
您可以使用ContentControl而不是Grid,并使用包含Grid的ControlTemplate / DataTemplate设置其Template / ContentTemplate属性
<ContentControl>
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ContentControl.Style>
</ContentControl>
或
<ContentControl>
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
...
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ContentControl.Style>
</ContentControl>