Content Presenter in WPF exception

896 Views Asked by At

Exception using content presenter

Type 'System.Windows.Controls.ContentPresenter' does not have a content property. Specify the name of the property to set, or add a ContentPropertyAttribute or TypeConverterAttribute on the type.

Below is the XAML

                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox IsChecked="{Binding IsSelected}" Content="{Binding Series}" Width="50" VerticalAlignment="Center" Checked="CheckSeries_Checked" Unchecked="CheckSeries_UnChecked" />

                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
3

There are 3 best solutions below

0
On

Well the only guess possible in this case is that you are trying to assign "content" property instead of "Content" with capital C. If it's not then post your XAML code please.

0
On

Have you tried using

Content="{TemplateBinding Content}"

Since it is a datatemplate, and the content will be set by the ItemSource used?

1
On

You are trying to set the ContentPresenter.Content property implicitly by setting the inner text of the ContentPresenter control:

<ContentPresenter>
    MyContent
</ContentPresenter>

Instead you should set it like this

<ContentPresenter Content="MyContent" />

You're getting this error because ContentPresenter doesn't have the ContentProperty Attribute which tells the XAML parser to set the inner text as the value for its Content property.