数据模板上找不到TargetType属性

4
<Grid>
    <ItemsControl ItemsSource="{Binding ScreenViewModelCollection}">
        <ItemsControl.Resources>
            <DataTemplate  x:Key="SomeKey" TargetType="{x:Type  local:RedScreenObject}">
                    <local:RedScreenObject/>
            </DataTemplate>
        </ItemsControl.Resources>
    </ItemsControl>
</Grid>

我不知道为什么它看不到TargetType属性。应该在Resources或ItemTemplate下面吗?我都试过了,但无论哪种方式都找不到它。

编辑: 为了获得更多的负分哈哈,这是参考以下内容: https://chat.stackoverflow.com/transcript/message/4295316#4295316


TargetType是<Style>标签的一个属性。 - Alex
3个回答

5

DataTemplate 只有一个 DataType 属性。


3
使用 DataType="{x:Type local:RedScreenObject}",而不是 TargetType。

没错。我觉得Rachel在她的示例代码中犯了个错误,谢谢。 - Lews Therin
那不起作用,只打印出引用,如下所示:WpfTut.ScreenObjects。 - Lews Therin

0

您可以在<Style下找到TargetType


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接