I'm learning XAML and universal windows apps at the moment. I've encountered an issue where I get an element not found (exception from HRESULT:0x80070490) and I can't seem to figure out where exactly that error is referring to. If I double click on it, VS opens the MainPage.xaml where <Page is underlined with the error.
It's nothing special... Just a collection of a few controls to play with.
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="Assets/320x480-1.jpg"/>
</Grid.Background>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="77,23,68,24">
<TextBox x:Name="HelloMessage" Text="Hello, World!" Margin="10" IsReadOnly="True"/>
<Button x:Name="ClickMe2" Content="Click Me!" Margin="10" HorizontalAlignment="Center" Click="ClickMe2_Click"/>
<Slider x:Name="slider" Margin="10" HorizontalAlignment="Center" VerticalAlignment="Top" Width="100" BorderThickness="0,50,0,0"/>
</StackPanel>
</Grid>
This is the exact error as copied from VS.
Severity Code Description Project File Line Suppression State
Error Element not found. (Exception from HRESULT: 0x80070490) Control D:\Dev\TestUW\App1\App1\MainPage.xaml 1
I tried removing the grid and the error persisted. I also verified that App1.MainPage existed as well. How can I figure out what exactly it's complaining about?
Too late now, but I ran into the same problem, copying the code from the MS OpenCV sample link (https://developer.microsoft.com/en-us/windows/iot/samples/opencv)
The problem was that you needed a space " " before the end of the first "page" tag. So instead of the code reading:
mc:Ignorable="d"> <-- missing space after "d"
it should read:
mc:Ignorable="d" >
Well the first thing i noticed is that your Page Tag is not closed or You just didn't copied that.Usually element not found could be caused due to calling something too early..You might consider using On_Loaded. If the problem is only that you haven't closed your Page tag make sure to do it after the Grid one ..
Related
Adding an external dll in simple "Hello World" UWP project is giving the two errors shown in the screenshot below:
NOTE: There are many online posts on such errors but most involve complex cases (adding images, using Telerik, ComponentOne tools etc) but this is just a simple text project just to test why adding a dll from a class library that does not do any image processing etc.is causing this issue.
Error [Click on the image to make it more readable]:
UPDATE:
My MainPage.Xaml file:
<Page
x:Class="UWP_Test4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWP_Test4"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="695,614,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<RichEditBox Name="rtbTest" HorizontalAlignment="Center" Height="532" Margin="0,10,0,0" VerticalAlignment="Top" Width="1480"/>
</Grid>
</Page>
Any idea what's wrong with the following (MVVM Light) code. It compiles fine but for some reason I cannot see a preview of the controls and I see a squiggly line in the EventToCommand (<GalaSoft_MvvmLight_Command:EventToCommand see picture below) but it seems to have the right namespace.
Any idea how can I fix it? Or this is simply the behavior expected when using MVVM Light?
FYI - Found a few similar questions about namespacing issues but my seem to be different since the code compiles fine.
<Window x:Class="MvvmControlChange.Content.MainPage.View.MainPageView"
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:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding MainPageViewModel,
Source={StaticResource Locator}}"
Title="Give me Liberty or Give me Smart Basic"
d:DesignHeight="360"
d:DesignWidth="488"
SizeToContent="WidthAndHeight">
<Button x:Name="Page2Button"
Content="Page 2"
Margin="0"
Grid.Row="1"
d:LayoutOverrides="Width, Height"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Custom:Interaction.Triggers>
<Custom:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="Page2ButtonClicked"Command="{Binding Page2Command, Mode=OneWay}" />
</Custom:EventTrigger>
</Custom:Interaction.Triggers>
</Button>
</Window>
Squiggly Line:
Reference Files:
For the record, here is the answer to my question.
https://blogs.msdn.microsoft.com/brada/2009/12/11/visual-studio-project-sample-loading-error-assembly-could-not-be-loaded-and-will-be-ignored-could-not-load-file-or-assembly-or-one-of-its-dependencies-operation-is-not-supported-exception-from/
I have a textbox within a page that binds to a model property that is validated, and when there is an error the error template is not shown!
A few points:
I have no validation issues for controls in there own window (not within a page displayed in a frame within a window).
The error template works, it is displayed for controls within a window.
The model is validating because the "Save" button within the page is disabled when a validation error is identified.
I "think" the problem lies with the fact that the control is within a page that is hosted within frame and thus the data context is not being passed to the page as it is seemingly isolated. Could that be the case? and if so how do I go about fixing this issue? and if not what else could it be?
The code (I have of course simplified the code to isolate the issue):
<Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
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:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
Height="576" Width="1163">
<Grid>
<TextBox HorizontalAlignment="Left" Text="{Binding Model.title, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
<Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
</Grid>
If I can add any further information or code please just let me know!
Problem solved - it transpires that Windows have a built in adorner layer but Pages do not, I would love to give you a detailed explanation as to why not but I don't know why (read below). But the solution is that you need to wrap your page contents in an adorner decorator to provide them with an adorner layer.
Just to be clear here is the "fixed" code:
<Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
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:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
Height="576" Width="1163">
<AdornerDecorator>
<Grid>
<TextBox HorizontalAlignment="Left" Text="{Binding Model.title, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
<Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
</Grid>
</AdornerDecorator>
If you know why pages don't implement the adorner layer and can provide a more insightful answer please feel free to add an explanation as another answer which contains the solution i.e. this and the explanation and I will change your answer to be the correct answer (instead of mine) - just to promote sharing knowledge ;)
I have add an Image resource for the wpf project am making by:
right-click on the Project -> Properties -> Resources -> Images -> From Existing -> ClientBackGround.png
and I made it background for the main window :
<Window x:Class="Illuminate_AutoPatcher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="1000" Height="750" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Window.Background>
<ImageBrush ImageSource="pack://siteoforigin:,,,/Resources/ClientBackground.png"/>
</Window.Background>
<Grid>
<Button Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Width="224" Margin="766,613,0,0" Height="124" >
</Button>
</Grid>
</Window>
but it's not working it's keep throwing this anoying error System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '6' and line position '10 , how I supposed to fix it, so I use static resources that's build with the project?
#HighCore is right, using application solves your issue in the given scenario
<ImageBrush ImageSource="pack://application:,,,/Resources/ClientBackground.png"/>
You still can use siteoforigin. For that you have to set the image property
Copy to Output Directory to "Copy always"
MSDN Link
I am new to wpf.I downloaded the wpf toolkit and then added it's dll file into my project file.Then tried some code to create watermark textbox but showing error(The tag 'WatermarkTextBox' does not exist in XML namespace).
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="TRAINING.WaterMark"
x:Name="Window"
Title="WaterMark"
Width="640" Height="480">
<extToolkit:WatermarkTextBox>
<extToolkit:WatermarkTextBox.Watermark>
<StackPanel Orientation="Horizontal">
<Image Source="Contact16.png" Stretch="None" />
<TextBlock Text="Enter First Name" Margin="4,0,0,0" />
</StackPanel>
</extToolkit:WatermarkTextBox.Watermark>
</extToolkit:WatermarkTextBox>
</Window>
Please help.
I have not used the wpf toolkit before, but I'm pretty sure that as you have added the namespace using xctk, then you should use that in the xaml - i.e. xctk:WatermarkTextBox instead of extToolkit:WatermarkTextbox
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="TRAINING.WaterMark"
x:Name="Window"
Title="WaterMark"
Width="640" Height="480">
<extToolkit:WatermarkTextBox>
<extToolkit:WatermarkTextBox.Watermark>
<StackPanel Orientation="Horizontal">
<Image Source="Contact16.png" Stretch="None" />
<TextBlock Text="Enter First Name" Margin="4,0,0,0" />
</StackPanel>
</extToolkit:WatermarkTextBox.Watermark>
</extToolkit:WatermarkTextBox>
</Window>
I Guess You Missed the refrence of that extToolkit so i added. i hope it will help you
My reason for this issue was confusion between xceed ($) vs dotnetprojects (Free) NuGet package.
So once I uninstalled the xceed, everything was working fine and error was resolved.