How to integrate Prism 7 WPF into old, large WinForms App - c#

I am attempting to integrate a (Prism 7) WPF Window into an existing WinForms app.
My window is defined as:
<Window x:Class="ESC.SV.UI.RAndDClient.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ESC.SV.UI.RAndDClient"
xmlns:core="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:prism="http://www.codeplex.com/prism"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="{Binding Title}" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<dxb:BarContainerControl Grid.Row="0">
<dxb:ToolBarControl Caption="Main Toolbar" BarItemHorizontalIndent="10">
<dxb:BarButtonItem Content="View 1" Glyph="{dx:DXImage Image=Forward_16x16.png}" Command="{Binding ExecuteView1Command}"/>
<dxb:BarButtonItem Content="View 2" Glyph="{dx:DXImage Image=Backward_16x16.png}" Command="{Binding ExecuteView2Command}"/>
</dxb:ToolBarControl>
</dxb:BarContainerControl>
<ContentControl prism:RegionManager.RegionName="ViewsRegion" Grid.Row="1" VerticalAlignment="Top"/>
</Grid>
When I launch the WinForms app and go to show this window, I get the following error message:
... which explains to override ConfigureRegionAdapterMappings method in the bootstrapper, but when I go to create a BootStrapper class that inherits from UnityBootstrapper, it says that this is now obsolete. I know that App is supposed to inherit from PrismApplication, but does this apply to a WinForms application as well?
Any advice on how to deal with this situation is greatly appreciated.

I know that App is supposed to inherit from PrismApplication, but does this apply to a WinForms application as well?
Prism is a WPF-application framework (and UWP and Xamarin). It does not support WinForms. That being said, you can use parts of Prism individually, of course, even without any GUI (the event aggregator, for example, would work fine in a windows service).
What do you want to use from the prism library? Basically, for each feature, you have to look what the bootstrapper does to initialize and configure it and then adapt that initialization and configuration to your app.

Related

UIRoot does not exist in the clr-namespace?

I am using an external library which generates an class for UI in my game from XAML, everything generates fine and it's working as intended except for one part. It says the Root element does not exist in the namespace and thus I cannot use the designer, the creator of the library himself doesn't even know why it is doing this, it works fine for him.
<!--ek:UIRoot was not found/ does not exist in the namespace-->
<ek:UIRoot
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"
xmlns:ek="clr-namespace:EmptyKeys.UserInterface.Designer;assembly=EmptyKeys.UserInterface.Designer"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<TextBlock Text="Hello World" Grid.Row="0" />
<TextBlock Text="This is EmptyKeys In monogame" Grid.Row="1" />
</Grid>
</ek:UIRoot>
And yet it does
The project is .net4.5 and anycpu the same as what the library is built on and i've rebuild the solution many times. (those were the solutions to similar issues)
Am I missing something?
I needed to unblock the dll because it came from another computer
http://blogs.msdn.com/b/delay/p/unblockingdownloadedfile.aspx
the example is a zip but it applies the same for dlls

Datagrid is not supported in a Windows Apps Project

I am trying to following along with this SO answer, however I am Visual Studio is complaining about the Datagrid is not supported in a Windows Apps project? Is there an alternative to Datagrid that I could use?
Ultimately I would like to create a grid of buttons that correspond to a MenuItem that is in a List menuLists.
I am new to databinding, so if anyone has better things I should be looking at, please let me know.
<Page
x:Class="App1.Pages.MenuItemsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<CollectionViewSource x:Key="MenuItemsCollectionViewSource" Source="{Binding MenuItems}"/>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid Grid.Row ="0" ItemsSource ="{Binding Source = {StaticResource MenuItemsCollectionViewSource}}" />
</Grid>
</Page>
I figured it out. I'm supposed to use GridView instead when I'm working on Pages.
Same problem solved for me when I changed Targer framework to .NET Framework 4.5. Originally it was NET Framework 3. It can be changed in project properties.
There is no control. There may be third party controls, or you can get similar layouts by templating a ListView.

Is there a way to display WPF Extended Toolkit's control in VS Designer?

I'm used to create my forms with the designer, and modifying the XAML manually only when needed.
Even though the extended toolkit is a fantastic library, it still lacks integration with Visual Studio's designer. Can, by any mean, the toolkit's controls be displayed in the designer (not the toolbox), like standard controls? And if not, is there an explanation?
For now, the toolkit's controls are just blank and unselectable with simple clicks.
NOTE: It seems that the issue happens with container components (like BusyIndicator and Wizard/WizardPage) only.
EDIT: Here's some of my XAML. With this, I can see the wizard's first page, but no obvious way to see the others. If I put my Wizard in a BusyIndicator, can't see a thing at all.
<Window x:Class="MyProgram.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProgram"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="My Program" Height="477" Width="688" MinWidth="688" MinHeight="478">
<xctk:Wizard x:Name="wizard" FinishButtonClosesWindow="True" Next="wizard_Next">
<xctk:WizardPage Name="Intro_Page" Title="ABC" Description="abc" NextPage="{Binding ElementName=Second_Page}" Enter="disallowNext">
<xctk:WizardPage.Content>
<Grid>
<Label Content="abc" HorizontalAlignment="Center" Margin="0,54,0,87" Name="intro_lbl" VerticalAlignment="Center" Grid.Column="1" Padding="5" HorizontalContentAlignment="Center" Height="28" IsEnabled="False" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Second_Page" Title="DFG" Description="dfg" NextPage="{Binding ElementName=Last_Page}">
<xctk:WizardPage.Content>
<Grid Name="grid">
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Name="txt_second" VerticalAlignment="Center" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Last_Page" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True" />
</xctk:Wizard>
</Window>
I know this answer comes late, but yesterday I was stumbling myself over this problem and maybe it is useful for others who land here.
I solved it by creating an own control derived from WizardPage.
Just Create a new UserControl, include the Xceed.Wpf.Toolkit namespace and change the Type from UserControl to xctk:WizardPage in the xaml file as well as in the code-behind file.
<xctk:WizardPage x:Class="WizardTest.MyWizardPage"
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"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:WizardTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock>Hello World!</TextBlock>
</Grid>
</xctk:WizardPage>
Now you can create your UI using the VisualStudio Designer.
To place your page in the wizard, simply put an object of you derived page into its items:
<xctk:Wizard>
<local:MyWizardPage Title="My Wizard Page"/>
</xctk:Wizard>
You can use Bindungs in your costum page out of the box because DataContext of the MyWizardPage object is set automatically to the wizards DataContext (which inherits from the Window DataContext if not explicitly given)

GUI bug on hiding ribbon

I've got a strange behavior with the Microsoft ribbon library (the library which is included in .Net Framework 4.5). If I hide the complete ribbon, the areas below the ribbon tab headers look really ugly. I've build a test application and was able to reproduce this behavior (screen below)
The code of this application is very simple:
<Window x:Class="RibbonLibraryTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Background="Yellow">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Ribbon Background="White">
<RibbonTab Header="Test1"></RibbonTab>
<RibbonTab Header="Test2"></RibbonTab>
<RibbonTab Header="Test3"></RibbonTab>
<RibbonTab Header="Test4"></RibbonTab>
</Ribbon>
</Grid>
</Window>
To hide the ribbon, I double click on one of the ribbon tabs like in MS Word.
Seems to be a bug in the ribbon library. Is there a way to avoid this?

WPF Ribbon: Maximized window going off screen

I'm using the System.Windows.Controls.Ribbon library for my application. Everything is working really nice, except when I maximize the window it starts to go off screen.
I also noticed that with other WPF applications but when you use a RibbonWindow it gets worse.
Here is my source code (nothing really exciting i think):
<RibbonWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.MainWindow"
Title="TestWindow" Height="350" Width="525" Background="LightSteelBlue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Ribbon Grid.Row="0">
<RibbonTab x:Name="TestRibbon" Header="TestRibbon">
<RibbonGroup>
<RibbonButton x:Name="TestButton" Label="Button" LargeImageSource="traffic_lights_green.png" />
</RibbonGroup>
</RibbonTab>
</Ribbon>
<ContentControl Grid.Row="1">
</ContentControl>
</Grid>
</RibbonWindow>
Is there some way to stop the window from doing this?
If you have not already found it, I think this may answer your problem.
systemmenu-does-not-show-correctly. It appears to be a bug specific to .net 4 implementation.
Just to let you know how I "solved" this. I'm using the Fluent Ribbon api. Which works much better for me, also you get the Office 2010 Styles.
But I highly recommend that you download the source code and compile it yourself because the last stable release was a while ago, but it's still under development and the developers respond very quickly to bugs.
http://fluent.codeplex.com/

Categories