Winform control getting cropped in WPF - wpf

I'm having problem trying to include a winform user control in WPF. My control gets cropped whatever I try to do.
The control keeps autosizing itself even when I have not set the option.
Here's what it looks like
Here's the XAML
<Window x:Name="mainForm" x:Class="RFID.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RFID"
mc:Ignorable="d"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:sp="clr-namespace:gei1076_tools;assembly=gei1076_tools"
Title="MainWindow" Height="350" Width="755.682">
<Grid>
<WindowsFormsHost>
<sp:SerialPortConfigurator x:Name="spcConfigurator" ></sp:SerialPortConfigurator>
</WindowsFormsHost>
</Grid>
</Window>
What am I missing?
Thanks

Related

TaskBar not shown when we set WindowChrome for Window

I set the system taskbar to autohide, then I ran the WPF application in Maximized state. When the application is in maximized state, I mouse hover the bottom of the screen to view the taskbar but it does not appear. Find the code block below.
<Window x:Class="_189619.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_189619"
mc:Ignorable="d" WindowState="Maximized"
Title="MainWindow" Height="350" Width="525">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="50" ResizeBorderThickness="3"/>
</WindowChrome.WindowChrome>
<Grid>
</Grid>
</Window>
Any workaround to show the TaskBar?
Thanks in Advance.
Regards,
Priyanga B

Use user control in xaml

I think I'm missing something very obvious.
I create a WPF application and a user control. Both within one project in Visual Studio. In the WPF application I want to use the user control but the compiler pretends not to know the user control:
Error 1 UserControl1 is not supported in a Windows Presentation Foundation (WPF) project
Here is the WPF application XAML:
<Window x:Class="WpfApplication1.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>
<UserControl1></UserControl1>
</Grid>
And this is the XAML code of my control
<UserControl x:Class="WpfApplication1.UserControl1"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Label>Hello World</Label>
You have missed declaration of the namespace in your xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:UserControl1></local:UserControl1>
</Grid>
</Window>

Align WPF window on startup

I have a WPF window which is positioned incorrectly when shown.
I want it to be positioned correctly, like this:
How may I accomplish this?
This is the xaml for the window:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication9.MainWindow"
Title="MainWindow" Height="1050" Width="910" Background="{x:Null}" >
There's a very handy XAML tag called WindowStartupLocation that allows you to specify where it starts. It is used like this:
<Window
...
Title="MainWindow"
Height="1050"
Width="910"
Background="{x:Null}"
WindowStartupLocation="CenterScreen">
This will start it in the center of the window where the mouse pointer is.
Edit: There is also an option called CenterOwner if you want it to always be the same monitor you start your app on.
Try the following (it will bind the top of your window to the top of the screen):
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication9.MainWindow"
Title="MainWindow" Height="1050" Width="910" Background="{x:Null}" WindowStartupLocation="Manual" Top="0">

How to add a page in another dll into a window in wpf

I created a new wpf application, with the default MainWindow.xaml,
and I created a new page: Page1.xaml with a button in it.
I want to embed the page in the window, so I tried:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525">
<Grid>
<WpfApplication1:Page1></WpfApplication1:Page1>
</Grid>
</Window>
Then I got a exception.
I searched here, and got another solution, using
so I tried this:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525">
<Grid>
<Frame Source="Page1.xaml"/>
</Grid>
</Window>
it worked.
But
what if the Page1.xaml is not in current project but in a dll file?
The general template to get resources from another assembly is : Source="pack://application:,,,/YourAssembly;component/Subfolder/YourResourceFile.xaml"
Take a look a this on MSDN

Outlook Add-in + WPF

Does anyone knows how to use WPF in Outlook Add-ins, I have read some blog posts and I realized that it's possible to add WPF controls in Outlook Add-in projects. I just want to host a complete WPF application in a Outlook Add-in. simple when outlook ribbon button clicks, it should open a WPF application, not a WPF controller hosted in a windows form, Can this be done?
Edited answer:
To use WPF in outlook Add-in projects, first add a WCF Usercontroller to the project and change the "UserController" to "Window" in both .XAML file and .CS file. Then you are done, You can do what ever you want with WCF.
Change this >>
<UserControl x:Class="AccessCachedContactsTest.UserControl2"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
to this >>
<Window x:Class="AccessCachedContactsTest.UserControl2"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</Window>
And also change the root class of .xaml.cs file to "Window".
To use WPF in outlook Add-in projects, first add a WPF UserControl to the project and change the "UserControl" to "Window" in both .XAML file and .CS file. Then you are done, You can do what ever you want with WPF. Change this >>
<UserControl x:Class="AccessCachedContactsTest.UserControl2"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
to this >>
<Window x:Class="AccessCachedContactsTest.UserControl2"
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"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</Window>
And also change the root class of .xaml.cs file to "Window".

Resources