I'm having an annoying error that I can't seem to fix or find a solution to in my WPF project. I have a custom WPF control that I added to my project but I can't get it to work. This is the error I am getting:
The tag 'ZoomBorder' does not exist in XML namespace 'clr-namespace:Namespace1;assembly=Namespace1'. Line 8 Position 10.
Here is my xaml for the window:
<Window x:Class="Namespace1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Namespace1;assembly=Namespace1"
Title="MainWindow" Height="350" Width="525">
<Grid Name="MainGrid">
<Label Content="Label" HorizontalAlignment="Left" Margin="357,165,0,0" VerticalAlignment="Top"/>
<local:ZoomBorder x:Name="border" ClipToBounds="True" Background="Gray"> //ERROR HAPPENS HERE
<Image Name="DrawingImage" HorizontalAlignment="Left" Height="200" Margin="10,10,0,0" VerticalAlignment="Top" Width="300"/>
</local:ZoomBorder>
</Grid>
</Window>
I have tried building, cleaning, and rebuilding with and without the offending lines and nothing has worked.
Anyone know how to fix this?
You have new visual studio and old lib. Thats mess.
Install 4.7 dev runtime:
https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk
Right click your project and open folder. Edit your project file to fav editor like notepad and add following lines:
<LangVersion>latest</LangVersion>
<TargetFramework>net47</TargetFramework>
goto where you use control and add namespace my visual studio 2022 suggest this one: <mainwindow.xaml>
xmlns:paz="clr-namespace:Scar.Common.WPF.Controls;assembly=Scar.Common.WPF.Controls.ZoomBorder"
close visual studio and restart and compile. Build: succeeded if you din't forget anything.
Related
I am new to XAML and WPF.
I am trying to add a placeholder to my textbox but I got this error: "The property 'PlaceholderText' was not found in type 'TextBox'" and "The member "PlaceholderText" is not recognized or is not accessible".
When I tried to type PlaceholderText, it didn't even show up in the auto-complete drop down list. "Header" has the problem.
I am using VS 2015 community and .NET Framework 4.5.2
Below is my code which I got it from https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.textbox#Examples
<Window x:Class="QuickGarbageSort.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:MyTestApp"
mc:Ignorable="d"
Title="MyTestApp" Height="550" Width="800">
<StackPanel>
<TextBlock Text="What's your name?"/>
<StackPanel Orientation="Horizontal" Margin="0,20,0,20">
<TextBox x:Name="nameInput"
Header="Enter your name:" PlaceholderText="Name"
Width="300" HorizontalAlignment="Left"/>
<Button Content="Hello button" Click="Button_Click"/>
</StackPanel>
<TextBlock x:Name="greetingOutput"/>
</StackPanel>
The documentation you got the code from is a documentation for Windows.UI.Xaml.Controls.TextBox, this is the textbox control used in Universal Windows Applications. This has a property called PlaceholderText
The WPF one is System.Windows.Controls.TextBox, this is different and doesn't have a PlaceholderText property. In order to have something like the UWP placeholder text in WPF, you have to implement it yourself or use a third party library which offers a control with this functionality.
I'm trying to understand WPF and have created a WPF test project. I've put a monkey01.jpg image in every folder starting from the project's root, moving up in hierarchy, to the debug folder. On the MainWindow I've created an Image and defined the source property to point to the monkey01.jpg and it displays correctly in design view. But when I run it, the image doesn't appear.
If I add the image file to the project as a resource, it will be displayed during runtime which is expected. (But this is not what I'm testing here)
If in the xaml file I write the absolute path as in Source="C:\Users\User\Desktop\visual_studio_projects\WpfApplication1\monkey01.jpg it will be displayed too.
But if I use a relative path (like in the example below), the image won't be displayed. It's as if upon execution, the program doesn't run inside the project folder and its subfolders; Instead it runs in some other location that has no access the image. Why this behaviour? What am I missing?
This is the MainWindow.xaml code:
<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="350" Width="525">
<Grid>
<Image x:Name="Thumbnailtest" Source="monkey01.jpg" />
</Grid>
</Window>
Thank you!
You need to set Copy to Output Directory in the Properties Window for the image to "Copy if newer".
Works fine here when I've set the image to Resource and don't copy, note I changed your monkey image to .png and I created a folder for it(Data/Images).
<Window x:Class="MasoneryLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MasoneryLibrary;assembly=MasoneryLibrary"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid>
<Image Source="Data/Images/monkey01.png" HorizontalAlignment="left" VerticalAlignment="Top" Width="290" Height="456" Margin="285,0,-58,-136" Stretch="None" StretchDirection="DownOnly"/>
</Grid>
</Grid>
Hmmmm.. is this a library? You should use URI packs to be safe.
With URI pack:
<Image Source="pack://application:,,,/MasoneryLibrary;component/Data/Images/monkey01.png" HorizontalAlignment="left" VerticalAlignment="Top" Width="290" Height="456" Margin="285,0,-58,-136" Stretch="None" StretchDirection="DownOnly"/>
Hope it helps!
Cheers,
Stian
In my daily work, I faced an issue regarding WPF XAML editor. For example, I will use Dynamic Data Display in my project. Firstly, I will add the DynamicDataDisplay.DLL to my project. And then I will add a specific xmlns for this DLL. But I found there is no IntelliSense for the added DLL, I need typed the namespace manually. Here is the code.
<Window x:Class="WPFMonitor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
Title="Monitor Window" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Text="CPU Usage" Margin="20,10,0,0"
FontSize="15" FontWeight="Bold"/>
<TextBlock x:Name="cpuUsageText" Margin="10,10,0,0"
FontSize="15"/>
</StackPanel>
<d3:ChartPlotter x:Name="plotter" Margin="10,10,20,10" Grid.Row="1">
<d3:ChartPlotter.VerticalAxis>
<d3:VerticalIntegerAxis />
</d3:ChartPlotter.VerticalAxis>
<d3:ChartPlotter.HorizontalAxis>
<d3:HorizontalIntegerAxis />
</d3:ChartPlotter.HorizontalAxis>
<d3:Header Content="CPU Performance History"/>
<d3:VerticalAxisTitle Content="Percentage"/>
</d3:ChartPlotter>
</Grid>
</Window>
As you can see, I have referenced the DLL in my XAML Code, but the editor give me the error about
The type 'd3:ChartPlotter' was not found. Verify that you are not
missing an assembly reference and that all referenced assemblies have
been built.
When I clicked the reloaded the designer. I tested this issue on VS 2010 SP1/VS 2013 Update2. But if I build this application. No errors, and it runs OK.
I am not an English speaker. if you cannot understand my question. please feel free to let me know. I will clarify it.
Any help would be appreciated!
Thank You very much! :)
I had a similar problem. A possible solution is get the source code if you can, and compile the .dll file yourself, then add it as a reference.
Worked for me in Visual Studio 15 when the .dll file I was using previously, was compiled in Visual Studio 13.
Hope it helps Someone :)
Well, I´m developing a wpf application and I got a strange error on design time. This is the code of a wpf form:
<Window x:Class="ViewLayer.Frm_EnrollWaitingList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Frm_EnrollWaitingList" WindowStartupLocation="CenterScreen" BorderBrush="{x:Null}" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="390" Width="410"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="NoResize">
<Window.Resources>
<ResourceDictionary Source="Dictionary/WaitingListDictorionary.xaml"/>
</Window.Resources>
<Grid>
<Rectangle Margin="0,0,0,0" Name="rectangle1" Stroke="{x:Null}" Fill="#FF8C90AD" Opacity="0.95" />
<Button Style="{DynamicResource CommonButton}" Content="Salir" Height="80" HorizontalAlignment="Left" Margin="166,234,0,0" Name="btn_close" VerticalAlignment="Top" Width="180" />
</Grid>
</Window>
The problem starts here:
<Window.Resources>
<ResourceDictionary Source="Dictionary/WaitingListDictorionary.xaml"/>
</Window.Resources>
The ResourceDictionary exits and in execution time it works perfectly. But at design time sometime when a want to modify the form in visual studio designer i get the following error:
FileNotFoundException An error occurred while finding the resource dictionary "Dictionary/WaitingListDictorionary.xaml".
Unable to find the specified file.
at Microsoft.Windows.Design.Platform.ViewProducerBase.Microsoft.Expression.DesignModel.DocumentModel.IDocumentRootResolver.GetDocumentRoot(String path)
at Microsoft.Expression.Platform.WPF.InstanceBuilders.ResourceDictionaryInstanceBuilder.ProvideResourceDictionary(IInstanceBuilderContext context, DocumentCompositeNode resourceDictionaryReferenceNode, IDocumentRoot& relatedRoot)
And I can not edit the form with the designer.
Any idea? I repeat on execution time I have no problems.
The Source property is relative, and you window appears to be in the ViewLayer directory, so the Dictionary folder must also be in the ViewLayer directory if you use
Source="Dictionary/WaitingListDictorionary.xaml".
If the Dicionary folder is at the root level, try
Source="/Dictionary/WaitingListDictorionary.xaml".
You can also use a pack:// URL.
I could figure it out!
There was an error on the ResourceDictionary I was trying to use. I fixed it, and voila! Everything works like a charm.
I've created a test Silverlight 2 app in Visual Studio, just copying the Tim Heuer video, but when I go to open it in Blend I get this error
UserControl is not supported in a Windows Presentation Foundation (WPF) project
This is the XAML code
<UserControl x:Class="MyFirstApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<TextBox x:Name="myTextBox" FontSize="60" />
<Button Content="Click Me" FontSize="60" Click="Button_Click" />
</StackPanel>
</Grid>
</UserControl>
Am I missing a reference or something?
You need to install Expression Blend 2.0 SP1.
Please take a look at this thread:
http://social.expression.microsoft.com/Forums/en-US/blend/thread/33030347-c99a-4f41-8be7-089c92e4ab2d