Пользовательский ContentControl не отображает контент после шаблонов? - PullRequest
0 голосов
/ 25 февраля 2011

Я создал новый пользовательский элемент управления DataGridInsertRowPresenter, который наследуется от ContentControl. Все работало хорошо.

Затем я добавил новый стиль, который меняет шаблон для него и больше не отображает содержимое. Вот элемент управления:

public class DataGridInsertRowPresenter : ContentControl {
    static DataGridInsertRowPresenter() {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGridInsertRowPresenter), new FrameworkPropertyMetadata(typeof(DataGridInsertRowPresenter)));
    }
}

Вот мой шаблон:

<Style TargetType="{x:Type Primitives:DataGridInsertRowPresenter}" BasedOn="{StaticResource {x:Type ContentControl}}" >
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate>
                <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Что не так с моим кодом?

Ответы [ 2 ]

0 голосов
/ 10 октября 2011

Вам необходимо добавить TargetType к вашему ControlTemplate, поскольку Control не имеет свойства с именем Content:

<ControlTemplate TargetType="{x:Type Primitives:DataGridInsertRowPresenter}">
0 голосов
/ 26 февраля 2011

Возможно, в вашем файле assemblyinfo.cs отсутствует атрибут, указывающий, где искать ресурсы. Убедитесь, что у вас есть следующий код в файле assemblyinfo.cs:

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)

)]

И убедитесь, что ваш стиль находится в Themes \ Generic.xaml (или указан как объединенный словарь)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...