Dynamic Telerik RadOutlookBar headers come out wrong with ItemTemplate

天大地大妈咪最大 提交于 2019-12-23 03:44:05

问题


I'm trying to use Telerik RadControls in a MVVM kind of way but having some strange problems.

The Viewmodel behind the RadOutlookBar has a collection of ViewModels that each have a Title string property. I wanted to define it so way the they get Wrapped inside a RadOutlookBarItem and bind the header/title properties together.

XAML:

<telerik:RadOutlookBar x:Name="Items">
    <telerik:RadOutlookBar.TitleTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding Path=Title}" />
        </DataTemplate>
    </telerik:RadOutlookBar.TitleTemplate>
    <telerik:RadOutlookBar.ItemTemplate>
        <DataTemplate>
            <telerik:RadOutlookBarItem Header="{Binding Path=Title}" >
                <ContentControl Content="{Binding}" />
            </telerik:RadOutlookBarItem>
        </DataTemplate>
    </telerik:RadOutlookBar.ItemTemplate>
</telerik:RadOutlookBar>

This works as intended except that the Header comes out strange. Instead of being like a static string item it seems to get wrapped inside another object that behaves like a similar to a RadOutlookBarItem ( it' changes color when mouseover and such )

Even if I cahnge to straightforward string instead of binding it's still strange. But If I don't define a ItemTemplate inside the RadOutlookBar (that is, not a dynamic control) it looks all right.

What could be going on there?


回答1:


Solved this and another problem in one fell swoop. I was binding to the wrong Template the whole time. This made me think I had to add OutLookBarItem myself.

In the end I was supposed to bind what I was trying to bind to the ContentTemplate.

<telerik:RadOutlookBar x:Name="Items">
    <telerik:RadOutlookBar.ContentTemplate>
        <DataTemplate >
            <ContentControl Content="{Binding}" />
        </DataTemplate>
    </telerik:RadOutlookBar.ContentTemplate>
    <telerik:RadOutlookBar.TitleTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding DisplayName}" />
        </DataTemplate>
    </telerik:RadOutlookBar.TitleTemplate>
    <telerik:RadOutlookBar.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding DisplayName}" />
        </DataTemplate>
    </telerik:RadOutlookBar.ItemTemplate>
</telerik:RadOutlookBar>

Should work I think.



来源:https://stackoverflow.com/questions/11136995/dynamic-telerik-radoutlookbar-headers-come-out-wrong-with-itemtemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!