动态Telerik RadOutlookBar标题出来错误的ItemTemplate [英] Dynamic Telerik RadOutlookBar headers come out wrong with ItemTemplate
问题描述
我试图以MVVM的方式使用Telerik RadControls,但有一些奇怪的问题。
I'm trying to use Telerik RadControls in a MVVM kind of way but having some strange problems.
RadOutlookBar后面的Viewmodel有一组ViewModel,每个有一个标题字符串属性。我想定义它,以便它们被包含在RadOutlookBarItem中,并将标题/标题属性绑定在一起。
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>
这个工作原理除了标题出来很奇怪。而不是像一个静态的字符串项,它似乎被包装在一个类似于RadOutlookBarItem的行为类似的另一个对象(它会在鼠标悬停等等时更改颜色)
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 )
甚至如果我呵呵直接的字符串而不是绑定它仍然是奇怪的。但是如果我没有在RadOutlookBar中定义一个ItemTemplate(也就是说,不是一个动态控件),它看起来就没问题。
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.
可能会发生什么? p>
What could be going on there?
推荐答案
一举解决了另一个问题。我一直在绑定错误的模板。这使我觉得我自己添加了OutLookBarItem。
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.
最后我应该绑定我试图绑定到ContentTemplate。
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>
应该工作我想。
这篇关于动态Telerik RadOutlookBar标题出来错误的ItemTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!