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>
Related
This might be simple but I do not know how to go about it. I want to attach a CollectionViewType like this: CollectionViewType="ListCollectionView" to a CollectionViewSource. I am using a typed DataSet and the CollectionViewSource was generated through a Drag and Drop. I am using a DataSet and not Entity Framework.
I have put the following references:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
However, I am failing to modify the CollectionViewSorce accordingly.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow"
Width="500"
Height="400"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<Window.Resources>
<local:DataSet1 x:Key="DataSet1" />
<CollectionViewSource x:Key="ExpenseDescriptionsViewSource" Source="{Binding ExpenseDescriptions, Source={StaticResource DataSet1}}" />
</Window.Resources>
<Grid >
</Grid>
</Window>
All the examples I have seen deal with Entity Framework and not with DataSet.
How can I implement CollectionViewType changes in the CollectionViewSource above using DataSset?
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
Ok, I have to say that I just started using WPF and I know nothing about XAML, so for my first project with WPF, I'll be trying to build my own app for my own buisness, But im getting a problem trying to get an image resource.
This is what I tried
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="605.027" Width="1042.214" WindowStyle="None" Background="{StaticResource Circuits}">
<Application.resource>
<ImageBrush x:Key="Circuits" ImageSource="Circuits.jpg"/>
</Application.resource>
</Window>`
But at the <Application.resource> line I'm getting the error
Do not recognize or can not access the member "resource"
and I just dont know what to do
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="605.027" Width="1042.214" WindowStyle="None" Background="{StaticResource Circuits}">
<Window.Resources>
<ImageBrush x:Key="Circuits" ImageSource="Circuits.jpg"/>
</Window.Resources>
</Window>`
Have you tried :
<Application.Resources>
So in your exemple :
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="605.027" Width="1042.214" WindowStyle="None" Background=" {StaticResource Circuits}">
<Application.Resources>
<ImageBrush x:Key="Circuits" ImageSource="Circuits.jpg"/>
</Application.Resources>
</Window>
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">
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