I'm using Prism and have a region that is a TabControl. I have a DataTemplate on the TabControl.ItemTemplate set to an interface of type IView. IView has a Title and Description string. When I call RegisterViewWithRegion with my IView, the tab is added but no description is shown on the header. Can I not bind to properties on an interface or am I missing something else?
manager.AddToRegion("ContentZone", new PrimaryView()); //Implements IView
<TabControl x:Name="ContentZone" cal:RegionManager.RegionName="ContentZone" Grid.Row="1" umn="0">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type oasis:IView}">
<DockPanel ToolTip="{Binding Path=Description}">
<Label Padding="0"
Content="{Binding Path=Title}"
VerticalAlignment="Center" />
Edit: I found a solution, although I don't find it all that great. For some reason the DataContext of the DataTemplate was always coming back as null no matter what I did, I tried the DataTempalteSelector, but the item itself was also null. I tried changing to a base abstract class instead, and nor did that work. So this is what I ended up with for the binding itself:
{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContentControl}}, Path=DataContext.Title}
-
You cannot associate a
DataTemplatewith an interface. It must be directly associated with the type. If you want to associate via an interface, you could consider implementing aDataTemplateSelectorthat checks whether the item implementsIViewand returns aDataTemplateaccordingly.HTH, Kent
thedesertfox : So I gave that a shot, but the item being returned in the SelectTemplate method always is null. I registered it like below. The breakpoint hits, but item is null.
0 comments:
Post a Comment