I am struggling to put a ContentPresenter in a Toolbar. I have a UserControl, DashboardView, with a viewmodel, DashboardViewModel. My ContentPresenter is set up like so:
in the UserControl.Resources, I have:
<DataTemplate DataType="{x:Type DashboardVM:DashboardViewModel}">
<Dashboard:DashboardView />
</DataTemplate>
and in the toolbar:
<ToolBarTray Margin="0" DockPanel.Dock="Top">
<ToolBar Band="0" BanIndex="0">
<--! other stuff -->
<ToolBar Band="0" BandIndex="1" MinWidth="500" ToolBarTray.IsLocked="True">
<ContentPresenter Content="{Binding Path=DashboardViewModel}" />
</ToolBar>
</ToolBarTray>
The ContentPresenter does not appear when executing. The other ToolBar does.
I’ve put the ContentPresenter outside of the toolbar in a Grid and it appears fine. So it’s something with the ToolBar, but I cannot figure out what.
UPDATE: I’ve also attempted (among many things) putting the ContentPresenter in a MenuItem, like this:
<ToolBar Band="0" BandIndex="1">
<MenuItem>
<MenuItem.Header>
<ContentPresenter Content="{Binding Path=DashboardViewModel}"/>
</MenuItem.Header>
</MenuItem>
</ToolBar>
Still not showing up.
More info:
DashboardView:
<UserControl x:Class="Wsi.Common.View.Dashboard.DashboardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Dashboard="clr-namespace:Wsi.Common.ViewModel.Dashboard"
xmlns:view="clr-namespace:Wsi.Common.View.Dashboard"
MinWidth="500"
MinHeight="30"
MaxHeight="70">
<UserControl.Resources>
<DataTemplate DataType="{x:Type Dashboard:DashboardItemViewModel}">
<view:DashboardItemView />
</DataTemplate>
</UserControl.Resources>
<StackPanel MaxHeight="70" Orientation="Horizontal">
<ContentPresenter x:Name="fileSystemDashboardItem" Content="{Binding Path=FileSystemDashboardItemViewModel}" />
<ContentPresenter x:Name="spreadHealthDashboardItem" Content="{Binding Path=SpreadHealthDashboardItemViewModel}" />
<ContentPresenter x:Name="spreadStatsDashboardItem" Content="{Binding Path=SpreadStatsDashboardItemViewModel}" />
<ContentPresenter x:Name="acquisitionStatsDashboardItem" Content="{Binding Path=AcquisitionStatsDashboardItemViewModel}" />
<ContentPresenter x:Name="backhaulHealthDashboardItem" Content="{Binding Path=BackhaulHealthDashboardItemViewModel}" />
<ContentPresenter x:Name="serverHealthDashboardItem" Content="{Binding Path=ServerHealthDashboardItemViewModel}" />
</StackPanel>
DashboardViewModel simply holds properties as above for the sub-viewModels, just {get; set;}
As mentioned before, this worked beautifully in a row by itself in the View, above the ToolBarTray.
TIA!
Janene
Answering my own question… there was nothing wrong with my code. The items in the Contents of the ContentPresenter exceeded the width of the toolbar. The toolbar displayed nothing as the contents were too wide.
An entire day chasing a bug that just needs me to make my s**t smaller and smarter about resizing.