本文介绍了WPF-TemplateBinding无法识别成员内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个包含以下资源的窗口

Alright, so I have a window with the following resources

<Window.Resources>
    <Style TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <TextBlock Text="{TemplateBinding Content}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

我收到一条错误消息,指出成员内容"未被识别或无法访问."我在做什么错了?

I am getting an error saying that, "The member "Content" is not recognized or is not accessible."What am I doing wrong?

推荐答案

您将必须在ControlTemplate上定义TargetType

You will have to define TargetType on ControlTemplate

 <ControlTemplate TargetType="Button">
     <Grid>
         <TextBlock Text="{TemplateBinding Content}"/>
     </Grid>
 </ControlTemplate>

这篇关于WPF-TemplateBinding无法识别成员内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:14