I am in the process of converting a VB.NET PRISM Module to C#. It is a very simple affair that currently works in VB.NET. It displays a string value that is bound to a ViewModel.
The XAML for the View (I switched it to hard-coded text in an effort to force its display, normally it is a databound control):
<UserControl x:Class="StatusBarAlarmsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
MinWidth="150">
<Grid>
<TextBlock Text="Garrison" VerticalAlignment="Center"/>
</Grid>
</UserControl>
The following code works in VB to display the View:
regionManager.RegisterViewWithRegion(RegionNames.statusBarRegion,
Function() container.Resolve(Of iSBAlarmsPresenter).view)
I attempted the same thing with converted C# code, and it looks like this:
this.regionManager.RegisterViewWithRegion(RegionNames.statusBarRegion,
() => new StatusBarAlarmsView());
I have tried multiple permutations of the above C#, all without success:
// One
var statusbarRegion = regionManager.Regions[RegionNames.statusBarRegion];
var test = new StatusBarAlarmsView();
test.ViewModel = new AlarmViewModel(this.logger, this.eventAggregator, null,
this.container);
statusbarRegion.Add(test);
// Two
this.regionManager.RegisterViewWithRegion(RegionNames.statusBarRegion,
() => container.Resolve<iSBAlarmsPresenter>().View);
I won't go into the detail of how the View and ViewModel hook up, because currently I'm not concerned about that--I just want it to display "Garrison".
Additional Info
Using Snoop, I can drill down into the StatusBar Region. I can see the other items displayed in that region, and they all have their DataContexts set as expected.
With my Alarm Module, however, the ContentPresenter does not have an inherited DataContext, it is marked as Local, which is different from all of the other items in the region. When I attempt to view the DataContext of the bottommost ContentPresenter, I am told the "object is NULL".
All of this is beside the point, though, because my View is being loaded into the tree, and yet my TextBlock is not displaying.
Updates
As requested, XAML markup for the StatusBar Region:
<Grid Name="StatusBarGrid" Grid.Row="3" Height="30">
<e:Interaction.Behaviors>
<behaviors:GridHeightModifyOnFontChangeBehavior FontSize="{DynamicResource AppFontSize}"/>
</e:Interaction.Behaviors>
<DockPanel >
<WrapPanel DockPanel.Dock="Right" cal:RegionManager.RegionName="{x:Static inf:RegionNames.statusBarRightRegion}" Orientation="Horizontal" Background="{DynamicResource ControlBackgroundBrush}" />
<StatusBar DockPanel.Dock="Left" cal:RegionManager.RegionName="{x:Static inf:RegionNames.statusBarRegion}" />
</DockPanel>
</Grid>