我在Tile控件中設置ControlTemplate(在Telerik TileList中)。它看起來是這樣的:如何設置ControlTemplate的DataContext?
<ControlTemplate TargetType="{x:Type telerik:Tile}">
<Border>
<!-- Some Content that binds to DP on the view models -->
<ContentPresenter Content="{Binding}" />
</Border>
</ControlTemplate>
在別處:
<telerik:RadTileList ItemsSource="{Binding ComponentViewModels}">
而且我有,將平鋪的ContentPresenter中呈現的項目定義的DataTemplates。我遇到的麻煩是,當一個ComponentViewModel被添加到ItemsSource(ComponentViewModel ObservableCollection)的目標中時,會出現一個新的Tile,但它的DataContext是RadTileList的ViewModel而不是單個組件的ViewModel。
我是否錯過了關於DataTemplate在ControlTemplate中的設置?
聽起來像是一個telerik bug。遵循WPF的ItemsControl概念,ItemContainers(在這種情況下爲'Tiles')應該將其datacontext設置爲ItemsSource集合中相應的項目。與任何其他基於'ItemsControl'的UI元素完全相同。 –
我已經打開Telerik的門票。我希望不是這樣... –