UWP build error - Duplicate Entry and Conflicting values for resource - c#

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>

Related

WPF form application doesn't have the same properties as in the designer

I'm learning how to create wpf controls (and windows) with Visual Studio 2019. As a first step, I've tried to generate a Window with a label inside. Using the following code, it looks like this (designer window)
<Window x:Name="Ventana" x:Class="PhanUtils.Sistema.Recursos.Ventanas.Mensaje"
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"
xmlns:local="clr-namespace:PhanUtils.Sistema.Recursos.Ventanas"
Width="580" Height="175" MinWidth="580" MinHeight="175" MaxWidth="580" MaxHeight="175"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
HorizontalAlignment="Center">
<Grid>
<Label x:Name="L_Informacion" Content="Label" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="554" Height="126" BorderBrush="#FFCF1E1E" BorderThickness="5"/>
</Grid>
</Window>
However, when I run the application and I show the same dialog, it looks like this:
Does anybody know why I'm having this issue?

Image is blank when program is run

When I add an image from my WPF project and use a resource for the source, it looks ok in the designer:
Main window in designer
My code is:
<Window x:Class="WpfPlay.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:WpfPlay"
mc:Ignorable="d"
Title="MainWindow" Height="271.107" Width="392.316">
<Grid>
<Image x:Name="image" HorizontalAlignment="Left" Height="128" Margin="22,22,0,0" VerticalAlignment="Top" Width="342" Source="pack://siteoforigin:,,,/Resources/logo.jpg" />
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="137,185,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
However I find that when I run the program, although the text box can be seen, the image is blank.
#Clemens has the correct answer - set the build action of the image file to resource
file properties
Just to add useful hint to #Clemens comment: if your logo.jpg file included in the same project as control, then after typing Source="pack://application:,,,/ you can press Ctrl+Space, and visual studio would show you a helper message about what file you can reference.

"element not found" = 0x8000490

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 ..

Custom xmlns namespaces not working

I am trying to follow these instructions for separating tab content into separate files. Here is my file structure
I am trying to load file 2's content with file 1 so that they work together. Here is file 2:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl x:Key="Tab1Control">
<DataTemplate DataType="TabItem">
<TextBlock Text="Test text"></TextBlock>
</DataTemplate>
</UserControl>
</ResourceDictionary>
And the relevant portion of file 1:
<Window x:Class="MnMCharacterCreator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tabs="TabContent/TabAttributesContent">
...
<!--Creates a tabbing system, with a grid defined by each ItemsControl-->
<TabControl Name="WindowTabs">
<TabItem Name="WindowTab1" Header="Attributes">
<!--This is where the UserControl from file 2 should be loaded-->
After visiting these two related questions (with tens of others) and asking on C# chat, I'm left thinking that this is unusual:
Intellisense shows nothing for <tabs: and even if I manually type an existing name or something, an error message is given, meaning that it is not a designer issue. Here is the full solution in VS2012.
To be specific, the question I am trying to ask is how can I use content from another xaml file? If xmlns isn't possible, what is?
You may want to create a user control for tab item as ,
<UserControl x:Class="WPFSample.TabItem1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<TextBlock Height="100" Width="100" Text="Hi from tab item 1"/>
</Grid>
Then for using this add the namespace in the MainWindow as :
<Window x:Class="WPFSample.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"
xmlns:local="clr-namespace:WPFSample">
<Grid>
<TabControl>
<TabItem Header="XYZ">
<local:TabItem1/>
</TabItem>
</TabControl>
</Grid>
You are ready to use .
Hope you have changed the usercontrol xaml.cs from XYZ : Window to XYZ : UserControl and build the solution once .

issue in watermark textbox

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.

Categories