I've created a .DLL in WPF. To use it in existing Windows Forms application I use ElementHost.
ElementHost eleHOst = new ElementHost();
UserWarps userWarps = new UserWarps();
eleHOst.Child = userWarps;
eleHOst.Dock = DockStyle.Fill;
UserWarps is in WPF .DLL which has been add-referenced. Now the file does lot of 3D manipulations. I'm also using Petzold.Media3D for 3D lines for wireframe modelling. Everything's working fine except that WireLines of Petzold.Media3D is not drawing any lines. If I reference the DLL from other WPF applications everything's fine, but hosting the UserControl of wpf in windows forms eliminates the lines/wireframes. Rest everything is perfect - MeshGeometry3D, Models, Visuals, functionalities etc.
Please suggest the way forward. could any alternative to ElementHost work? If it does then what is it?
Adding answer originally added by OP in question as I don't want this question to
be closed just because of that.
Petzold has mentioned here that hosting wpf in Windows forms causes the Wire frames to disappear. He also posts a work around which is very simple and worked perfectly:
NOTE: For reasons discussed in paragraph 5, these Wire classes will
not work when
you're hosting 3D in Windows Forms, or when you're trying to print a 3D scene. To make it work, try replacing the static
OnRendering method in WireBase with the following:
static void OnRendering(object sender, EventArgs args)
{
foreach (WireBaseAndUltimateParent wirebaseAndParent in listWireBases)
{
WireBase wirebase = wirebaseAndParent.wirebase;
wirebase.OnRendering();
}
}
Related
I'm developing a simple application. I got two projects in the solution
1 WPF Custom Control Library
2 Windows Forms Application
I'm rendering some 3D visualization on WPF and I got that embedded in the windows form as UserControl. So here is what I need to do in this project.
I've got
public void BuildObjectTest(InsertionPoint insertionPoint, Points point) that visualize one object.
Anyway I want it multiple times from my windows Form application because I need to show several objects. I've got a textbox that when I write "barcode" I've got several object items in a LIST that show some label information and buttons PREVIOUS and NEXT. So I have to think in that way is it possible to add code in the constructor runtime or is there any other way I can do that?
This is how the constructor looks like:
public UserControl1()
{
InitializeComponent();
InsertionPoints insertionPoint=new InsertionPoint(0,50,48);
Points points=new Points(100,50,20);
BuildObjectTest(insertionPoint,points);
VisualizeBoxSides();
}
To update UI in WPF Form, I had to use:
userControl.Dispatcher.Invoke(() =>
{
userControl.BuildObjectTest(insertionPoint,points);
});
I have a scrollView with a Grid inside which contains several Entrys.
When I click anywhere on the screen that isn't one of the Entry controls the focus automatically goes to the first Entry I have on the grid. I.e. This happens whether any Entry already has Focus or not, it will always set the focus of the first one again.
If I remove the Scrollview and have the Grid on screen on it's own I don't get this issue.
I am developing an application for a Windows 10 device but using the Xamarin forms cross platform code as we may move the code to Android at some stage.
Thanks in advance.
I was able to reproduce the described behavior on UWP Windows 10, but not on Android or iOS, so this is a bug in the Forms code for UWP.
I have filed a bug report for this issue which you can track here: https://bugzilla.xamarin.com/show_bug.cgi?id=52613
Xamarin engineers will now discuss this issue on the bug report. If you would like to receive a notification when the bug is updated, you can add yourself to the CC list for the bug. Please note that you will need to create an account on that system if you have not already done so.
I don't know if you solved your problem because it was more than a year ago and the issue #jgoldberger has opened on Xamarin's Bugzilla did not progress since last October.
Nevertheless I just noticed the same behaviour on my UWP app and after looking around the internet I found a solution.
If you look at this thread : Why does my TextBox get focused when clicking inside of ScrollViewer?
Then it is easy to imagine a solution for a Xamarin.Forms app by creating a custom renderer inside your UWP project.
You can use the following code which is working perfect for me :)
using {your_project_namespace}.UWP;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(ScrollView), typeof(ScrollViewCustomRenderer))]
namespace {your_project_namespace}.UWP
{
public class ScrollViewCustomRenderer : ScrollViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Control.IsTabStop = true;
}
}
}
Hope this helps.
Cheers
I'm working on an WinForms replacement app in WPF 4.5.
The current WinForms app streams video from a C++ component. The C# WinForms control has this code:
public void StartVideoStream(int iCamera)
{
if (InvokeRequired)
{
delStartVideoStream del = new delStartVideoStream(StartVideoStream);
Invoke(del, new object[] { iCamera });
}
else
{
if (!VideoPlaying)
{
int iSuccess = ClientComm.StartVideoStream(iCamera, ucVideoPlayer.Handle,
(ClientComm.streaming_protocols)Properties.Settings.Default.VideoStreamProtocol,
Properties.Settings.Default.VideoStreamFrameRate);
if (iSuccess != 0)
{
Debug.WriteLine("[ucVideo] Could not play video.");
}
}
else
{
ClientComm.SelectVideoStream(iCamera);
}
VideoPlaying = true;
}
}
You can see that it passes its handle to the COM component which writes the video directly to it.
The problem is that in WPF controls do not have handles. How can I do this I WPF?
Thank you.
The only way I've seen this done is to host a WinForms control inside the WPF control using a HwndHost (https://msdn.microsoft.com/en-us/library/system.windows.interop.hwndhost%28v=vs.110%29.aspx). Unfortunately this lands you right back in WinForms territory.
HwndHost is a little involved to cover in a sensible answer, but there's a reasonable tutorial here: http://blogs.msdn.com/b/ivo_manolov/archive/2007/10/07/5354351.aspx
You should be able to get some useful pointers from the Vlc.DotNet library (https://github.com/ZeBobo5/Vlc.DotNet), which does something similar. Based on playing around with that, if you pass the handle of the WPF application window to a COM component the video is likely to overlay the entire window. If, on the other hand, you talk to the COM component from a WinForms component inside the WPF component, you can use the handle of the WinForms component and keep the rest of your window clear of obstruction.
I'm writing a Windows Phone 8.1 Store app and I need to create a control so that it looks and behaves similar to WP 8.1 system task switcher (that appears when holding back hardware button).
It should show some images and support sliding left or right when swiping. Does anyone know what control should I use or do I need to create a completely new control from scratch?
So, the sollution was easy. The control I was looking for was... a ScrollViewer. It has 2 properties in WinRT XAML that make the ScrollViewer scrolling behave like I wanted: HorizontalSnapPointsAlignment and HorizontalSnapPointsType.
If you want to try this behavior, this MSDN code sample will expose it for you.
One point to mention. If you wish to set such behavior to, for example, a ListView you should firstly get its internal ScrollViewer in code and then set its HorizontalSnapPointsAlignment and HorizontalSnapPointsType properties. You can use GetFirstDescendantOfType<T>() extension method from WinRT XAML toolkit.
var sv = myListView.GetFirstDescendantOfType<ScrollViewer>();
sv.HorizontalSnapPointsAlignment = SnapPointsAlignment.Center;
sv.HorizontalSnapPointsType = SnapPointsType.Mandatory;
I am currently building an application based on a real world scenario, to help me learn and understand WPF and MVVM. To that end I have read and worked through Karl Shifflett's "In The Box" VSIX, and I was able to adapt most of the concepts to the application that I am working on.
While I think MVVM is a powerful design pattern, it does (seemingly) make things that were once trivial (e.g. displaying messages, navigation, interacting with multiple window), not so trivial or straightforward. Now onto the crux of my problem / confusion.
The WPF application that I am working on is a Windows based application, and I am working from a set of basic requirements:
A basic login screen
After a successful login, close the login screen and open the actual application
Simulate a typical program workflow (opening "child" windows via button clicks, displaying modal windows, etc.)
Preform data validation / error handling
Log out
I am used to working with MDI Applications on a windows platform where interactions on a parent form cause child forms to open; I understand that MDI is not something that WPF supports and I am fine with approaching development from a different perspective. My UI would still work in a similar manner to a MDI application though: I have my application layout, and as I interact with that layout my application will respond by opening windows, displaying messages, and so on. It isn't clear to me (via MVVM) how to interact with multiple windows, or how well MVVM would scale to a large application with many windows / views.
I am not opposed to using something like Prism, but I haven't found a good article on how Prism approaches my particular problem very well. Any help, advice, feedback, or otherwise is greatly appreciated!
Have you tried looking at nRoute Framework?
A link can be found here
There are actually some good tuturials about prism
Link 1
Link 2 (Part II of Link1)
Link 3
For a more straight forrward application (not very complex and modular), you can always create a aplication, with a main window that manages child usercontrols (login window, menu window, other windows ...)
For example, create a window a contentpresenter in it, and in codebehind:
public partial class ShellWindow: Window
{
public enum PagesTypes { Login, Home }
PagesTypes currentOpenedPage;
LoginUserControl login;
HomeUserControl home;
public WindowController()
{
InitializeComponent();
login = new LoginUserControl ();
login.GoToPage += new LoginUserControl.ChangePageHandler(GoToPage);
GoToPage(PagesTypes.Login);
}
public void GoToPage(PagesTypes page)
{
switch (page)
{
case PagesTypes.Login:
//Close last opened usercontrol,
....
//open new usercontrol
login = new LoginUserControl();
contentpresenter.content = login;
break;
//other pages cases
....
}
currentOpenedPage = page;
}
}
And in for example the login usercontrol:
public partial class LoginUserControl : UserControl
{
internal delegate void ChangePageHandler(ShellWindow.PagesTypes toPage);
internal event ChangePageHandler GoToPage;
public LoginUserControl()
{...}
//Methods for login
.....
internal void LoginOK()
{
if(this.GoToPage != null)
GoToPage(ShellWindow.PagesTypes.Home);
}
}
You can build a good dynamic using this method changing usercontrols, simulating diferent windows.
Hope this gives you some ideas.
MVVMing your child windows actually can be kind of easy, especially if you decide that a tabbed interface is OK. Your outer window's view model simply has a collection of ChildWindowViewModel. You create a new tab just by creating the new view model, asking the outer window to add it to it's collection, and WPF's DataTemplate awesomeness will take care of the proper display. You'll have to do some fiddling to get tab 'close' operations working the way you want. It's kind of a pain but doable.
If you really want to do MDI, there's nothing built into WPF for it (I think Microsoft has decided that it is a bad UI pattern now?), but there may be 3rd party controls out there for it. Any good one will still mirror this solution where their MDI container control will bind to your list of child window view models.