The following is from my response to an issue in the Unity discussion forum. While addressing a workaround to an issue (assuming there is a better WPF way - which I can/will address in the future) I identified some simple steps to implementing the Unity EventBroker. I'll identify those steps below within the context of resolving the issue that JasonTeale required assistance with. Click the above referenced link for more information on Jason's issue.
My response follows - assumes user has download latest Unity package w/source:
I have a solution but please bear in mind that it may not be the correct solution; currently I'm investing my time in learning WPF and Unity and once I have them under my belt will attack the CompositeWPF (I should then know what I'm looking at); although I did cheat and had to figure out / understand how the RegionManager worked before I could move on ;)
For anyone who wants to visualize the problem:
1. Load the Commanding solution and change the Commanding.Modules.Order project's PresentationModels\OrdersEditorPresentationModel.cs InitialOrdersCount constant int from 3 to 25 - when you run the app you'll find the listbox has no scrollbars and it extends below the visible grid cell area (there will be 25 items in the list versus 3).
2. First we'll fix the scrollbar issue - Views\OrdersEditorView.xaml. Update the ListView element by adding x:Name="ListView1" and change the Height attribute from "Auto" to "200"; the listview will have scrollbars and fit nicely in the Grid cell.
3. The solution lies in Event notification - the view is nicely decoupled from the shell so it doesn't know when the shell size changes (perhaps the CompositeWPF framework has something to notify???); we'll let it know so that we can adjust the ListView1 height accordingly. Let's get two very useful Unity Projects (Event processing may be in CompositeWPF but again, I do not know it yet :)
a. Load the EventBrokerExtension and SimpleEventBroker projects from the latest Unity download (UnityQuickStarts\language\EventBroker\Src).
b. Set references to each in the Commanding and Commanding.Modules.Order projects
4. In the Commanding project's CommandBootStrapper.CreateShell method add the following statement before the Shell shell statement:
Container.AddNewExtension<SimpleEventBrokerExtension>(); // and add using/imports as applicable
5. Update your Commanding Shell XAML so that it will notify code behind when the size has changed:
<Window x:Class="Commanding.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF"
Title="Shell" Height="385" Width="500" MinHeight="385"
SizeChanged="Window_SizeChanged"
>
6. Update the Shell's code behind as follows:
[Publishes("ShellSizeChanged")]
public event EventHandler ShellSizeChanged;
public Shell()
{
InitializeComponent();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (ShellSizeChanged != null)
ShellSizeChanged(sender, e);
}
7. Update the OrdersEditorView code behind as follows:
[SubscribesTo("ShellSizeChanged")]
public void OnSizeChanged(object sender, EventArgs e)
{
SizeChangedEventArgs args = e as SizeChangedEventArgs;
ListView1.Height = args.NewSize.Height-160;
}
If we (you or I) didn't miss anything, when you resize the form your ListView1 control will resize accordingly
Tags:
unity,
eventbroker,
compositewpf
Categories:
CompositeWPF |
Unity