Hello everyone.
I have shell WinForms application that hosts WPF User Control contains RadDocking. When I drag RadPane, a RootCompass indicators of RadDocking shows in wrong location (see attachment). It looks like indicators shows without offset of embedded WPF Control relatively shell WinForms application.
Is it bug? Or maybe is there a way to change a location of RootCompass indicators?
Thank you.
8 Answers, 1 is accepted
I've prepared a simple example reproduces that bug. You can find it using link below.
WinFormsWPF.sln is solution of WPF User Control contains RadDocking.
WFHost.sln is solution of WinForms host application.
https://drive.google.com/file/d/0B1j-40J5aVOfWFlYZVFtTnJidzg/view?usp=sharingPlease check the following example from our online XAML SDK repository that demonstrates how to host RadDocking in WinForms application:
https://github.com/telerik/xaml-sdk/tree/master/Docking/DockingInsideWinForms
What you need to do in your application is to add reference to Telerik.Windows.Controls.dll in the WFHost project in order to implement a custom IWindowInteropabilityAdapter as shown here. Afterwards set the adapter to the WPF control. You can find below all the needed code:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
var wpfControl =
new
WpfHosted.UserControl1();
WindowInteropabilityHelper.SetWindowInteropabilityAdapter(wpfControl,
new
Adapter(
this
));
elementHost1.Child = wpfControl;
}
private
class
Adapter : IWindowInteropabilityAdapter
{
private
Form1 form;
public
Adapter(Form1 form)
{
this
.form = form;
}
public
int
AbsoluteLeft
{
get
{
return
this
.form.PointToScreen(
this
.form.elementHost1.Location).X; }
}
public
int
AbsoluteTop
{
get
{
return
this
.form.PointToScreen(
this
.form.elementHost1.Location).Y; }
}
public
IntPtr Handle
{
get
{
return
this
.form.Handle; }
}
}
}
Hope this helps.
Regards,
Kalin
Progress Telerik
Hi, Kalin.
Your solution is works. Thank you very much.
Hi,
I checked the example and observed that the Root Compass Location is not at the center of the screen but a bit displaced.
I have attached the screen shot here.
Hello Egor,
I was able to reproduce this with a DPI scale set to 125%. Can you confirm that this is your setting too?
Regards,
Martin Ivanov
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Martin,
Yes, I reproduced it with DPI scale set to 125%. This is still reproducible when the DPI scale is set to 100% or 150%.
Thanks and regards,
Shrikant Mahapatra
Hello Shrikant,
I was able to reproduce this only on a DPI different than 100%. This happens because the PointToScreen method used in the Adapter class doesn't take into account the currently applied DPI. To resolve this, you can get the current DPI of the monitor and update the AbsoluteLeft and AbsoluteLeft property implementations of the Adapter class. For example:
public int AbsoluteLeft { get { Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); var dx = graphics.DpiX / 96; graphics.Dispose(); return (int)(this.form.PointToScreen(this.form.elementHost1.Location).X / dx); } } public int AbsoluteTop { get { Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); var dy = graphics.DpiY / 96; graphics.Dispose(); return (int)(this.form.PointToScreen(this.form.elementHost1.Location).Y / dy); } }
Regards,
Martin Ivanov
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Martin,
This solution works. Thanks.
Regards,
Shrikant