I've been trying to use the Extended WPF Toolkit so that I can make use of the RichTextBoxFormatBar but I seem to be going round in cirlces. Despite trying several examples on here and other sites I keep getting the same error messages:
The attachable property 'FormatBar' was not found in type 'RichTextBoxFormatBarManager'.
The type 'toolkit:RichTextBoxFormatBar' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I'm new to WPF so I'm know it's something I'm not picking up on rather than a bug, can anyone tell me what I'm doing wrong and save my sanity?
<UserControl x:Class="TestWPF_Richtextbox.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"
xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<RichTextBox>
<toolkit:RichTextBoxFormatBarManager.FormatBar>
<toolkit:RichTextBoxFormatBar />
</toolkit:RichTextBoxFormatBarManager.FormatBar>
</RichTextBox>
</Grid>
</UserControl>
EDIT: Both the library and the project are .Net 4. The version of the WPFToolkit.Extended.dll is V.1.6.0.0.
My own stupid fault.
I'd forgotten to unblock the DLL when I downloaded it as per the instructions which say that after downloading the ExtendedWPFToolkit_Binaries.zip you should then right click on it, select "Properties" and then "Unblock".
Hopefully this post will help someone else who has made the same mistake.
I'm hardly a rookie - but had the same issue.
Frankly I've never heard of unblocking a .zip file. Like most people I just skimmed the instructions, after all I know how unzip a file - or so I thought.
I had fought with extended toolkit 1.9.0 for two hours because my app would compile, run and work, but VS12 designer couldn't render the window. THen I saw the above post about unblocking the zip before expanding. Thought to myself "whiskey tango foxtrot" is this guy talking about. But I was desperate, so I closed VS. Deleted my expanded files. This time did the unblock. THen expanded into the very same locations. Restarted Visual Studio and to my amazement the designer now renders the controls and don't complain about the WatermarkTextBox not being in the namespace etc.
Really a humbling experience about reading the directions more closely.
This same thing happened to me and I eventually figured out it was either because I had the dll or the solution stored on the network instead of my local computer. I moved both to the local computer and it started working.
Related
I'm trying to create a project dll file that holds core styles, resources, controls, etc. This will then be referenced into various other projects to use as a graphic base to unify the appearance.
Anyway, I have the graphics project set up and I can use it in other projects and it all seems to display correctly. However, XAML intellisense for my static resources doesn't seem to be working.
Here is my resource dictionary reference:
<ResourceDictionary Source="pack://application:,,,/BIT.GraphicElements;component/BITCoreStyles.xaml" />
As you can see I'm using pack notation to reference it inside it's assembly. I can style elements like I would expect (StButtonAction is in the above dictionary):
Style="{StaticResource StButtonAction}"
However, I have to type it in manually. Intellisense doesn't give it as an option but if I type it manually is applies it successfully. It also works if I add the project to the solution and reference it there, however this is intended to be used by those that don't necessarily have access to the graphics project so that's not a good solution in the long run...
What am I missing? Is there a way to make Intellisense work for these?
Maybe this'll help future searchers even if it doesn't fix your specific problem.
When you have a solution involves external dll then you can occasionally find resources just don't get loaded at design time. At all. Even though you merge in app.xaml the things don't turn up until you run.
It looks like some sort of subtle bug to me.
The way I work round this is to use functionality originally intended for Blend. We are now using the blend designer in visual studio.
In solution explorer, add a resource dictionary to Properties. Yes. Properties. Create it first in your project and drag it up there. This must be called DesignTimeResources. This can then merge any resource dictionaries you will want to use just for design time or when you have an issue makes you think resource dictionaries aren't getting loaded for design time.
Mine is in army editor but uses resources from a referenced dll, UILIb. It looks like:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ArmyEditor">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/UILibResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
This is a resource dictionary in a bit of an odd place but nothing particularly weird so far.
Next is the bit that many developers will never have done - editing your csproj.
Right click your project and choose unload.
Right click it again and edit it.
In there you will have entries for all the stuff makes up your project. And of course breaking this would be bad so maybe you want to back up first.
If you don't use blend then I think the important thing here is to add a node which says ContainsDesignTimeResources True, but here's mine:
<Page Include="Properties\DesignTimeResources.xaml" Condition="'$(DesignTime)'=='true' OR ('$(SolutionPath)'!='' AND Exists('$(SolutionPath)') AND '$(BuildingInsideVisualStudio)'!='true' AND '$(BuildingInsideExpressionBlend)'!='true')">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>
Save your edits.
Reload your project.
When the designer is open, you should find resources from it are loaded. Maybe this will help intellisense find them.
I mentioned this earlier but.. In my experience, such intellisense on resources is often unreliable.
This definitely solved a similar issue I have had in this solution. It is also useful when you want to temporarily overlay resource dictionaries for localisation/branding testing.
I'm using VS2013 Express. I'm quite new in WPF and MVVM. I've downloaded mvvmlight using NuGet to my project. I'm tryinng to use GalaSoft_MvvmLight_Command:EventToCommand. As far as I know, I have to add reference in xaml by adding namespace:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight"
But, unfortunatelly I get error, that says:
The tag 'EventToCommand' does not exist in XML namespace
'clr-namespace:GalaSoft.MvvmLight;assembly=GalaSoft.MvvmLight'.
I've found some information, that I have to include GalaSoft.MvvmLight.WPF45 assembly, but I don't see this dll in packages\MvvmLightLibs.5.0.0.1\lib\ folder. There are many folders, for each .NET version etc, but each of these assemblies names are the same, without WPF45 sufix.What is going on? Where do I find this GalaSoft.MvvmLight.WPF45.dll assembly? Or maybe in version 5 was some changes made in names?
Edit:
Using object browser I found that EventToCommand is in GalaSoft.MvvmLight.Platform assembly in GalaSoft.MvvmLight.Command namespace. So I did
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
I can compile project now, but I still get errors in xaml (what is weird):
A value of type 'EventToCommand' cannot be added to a collection or dictionary of type 'TriggerActionCollection'
and
The type 'EventToCommand' from assembly 'GalaSoft.MvvmLight.Platform' is built with an older version of the Blend SDK, and is not supported in a Windows Presentation Framework 4 project.
and xaml editor can't display window properly (invalid markup).
Edit2:
Solution for invalid markup.
After I've changed the namespace to xmlns:cmd="http://www.galasoft.ch/mvvmlight" I also change project's target framework from 4.5 to 3.5. IDE shows an error about there are few NuGet packages that target other framework, so I returned to 4.5 - and it magically works now ;). Thanks all for help.
Here's how its done now in your XAML assuming you've got Version 4.0.0. Beat 1 or higher:
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
I found this at the bottom the release notes here: http://www.mvvmlight.net/installing/changes/
Details
XmlnsDefinitionAttribute for GalaSoft.MvvmLight.Command in Extras assembly
Thanks to the addition of XmlnsDefinitionAttribute, you can simplify the inclusion of the MVVM Light EventToCommand action in XAML. See the before and after below:
Before:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
After:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
EventToCommand exists in the Extras assembly.
Try:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
More Information:
To determine the assembly a class falls in, I usually Go To Definition and the assembly is referenced in the region at the top of the [from metadata] code file.
I just spent several hours on an issue when using VS2012, WPF 4.5 and design-time data, specifically the DesignInstance attribute.
Goal: I wanted to have design-time data support in my WPF project (MVVM-based), both in VS2012 and Blend, and I could not for the life of me make the MVVMLight approach work consistently.
So I tried to change to "just" using the built-in support for design-time data, using the markup extension provided with Blend.
Problem: Consider the following code:
<Window x:Class="Nova.View.AlertsView"
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:Nova.View"
xmlns:vm="clr-namespace:Nova.ViewModel"
mc:Ignorable="d"
DataContext="{Binding Alerts, Source={StaticResource Locator}}"
d:DataContext="{d:DesignInstance vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
... />
Both VS2012 and Blend reports "the name DesignAlertsViewModel does not exist in the namespace clr-namespace:Nova.ViewModel", even though intellisense resolves it just fine, and you have checked a thousand times that the namespace and class name are both correct.
I ran into this error myself in VS2013 then found this question. After searching more, I found an answer that helped me solve it.
instead of
d:DataContext="{d:DesignInstance vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
use
d:DataContext="{d:DesignInstance d:Type=vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
I was using "...d:DesignInstance Type=vm:..." and that displays the same error described above. As soon as I add "d:" everything works.
Here is the thread I found that helped.
https://stackoverflow.com/a/21690404/2892400
Check if the "Platform target" in your build configuration is set to "AnyCPU". My was set to "x64", so the designer was complaining about the missing type.
VS is running in 32 bit so maybe there is an issue with executing code from 64 bit assemblies.
I found the solution when trying to open my UserControl in "Blend for Visual Studio". It displayed an neat exception to me.
P.S.: After using the accepted answer: Use "d:Type=vm:DesignAlertsViewModel" instead of "vm:DesignAlertsViewModel" my control was visible, but no example data was displayed.
Workaround: Make sure that the design-time data class is in the same namespace as the View itself. Once I moved my DesignAlertsViewModel to the View namespace, both the VS2012 and Blend designer immediately started working with the design-time data.
Update: This is a workaround for now, until I get to the bottom of the issues. However, in my case, this is the only way to make design-time data work consistently. Of course, if you go down this route you change the class names since - clearly - the DesignAlertsViewModel is no longer a view model. It is now simply a POCO containing design-time data. So perhaps AlertsDesignData would be a better name. I'm not overly happy with the fact my design-time data lives under my View namespace, but it works.
I also encourage you to take a look at Laurent's article from MSDN Magazine, April 2013. I like this approach, since it exercises the MVVM pattern a lot more: The design time data service/provider is injected via IOC, so your view models will get "exercised" even at design time.
Update 2: After spending yet another 4 hours on this, I think the jury is still out on which approach is the better: Should we go with simple POCO data classes or the MVVMLight approach, using IOC for design-time data services? The former is simple and requires less code, the latter is more true to the MVVM approach, and exercises the real view models to some degree and could possibly reveal some bugs along the way.
Also, I did have to restart VS a couple of times during my refactoring to the MVVMLight approach - design-time data simply disappeared and came back after a VS restart. However, right now it seems stable enough, and I cannot pinpoint this any further.
I've found that DesignInstance is not working in my .NET 3.5 and .NET 4.0 projects, whereas it works in >= .NET 4.5 project (the projects are the same, they share the same files by using links).
I've recently completed a fairly large (for one man) WPF project, and started coding something for fun. I was almost done with an app worthy of showing off to friends and colleagues, and I started playing with window sizes - manually resizing the window - just to see what would happen on various screens.
And what happened was - my window got corrupted for certain window sizes, especially at about 100x100 range. I got very confused, and started to remove parts from XAML, my code, everything. But the problem persisted.
Lastly, I created a brand new WPF project - I didn't even change the name - WpfApplication1 it's called. Surely, same artifacts appear. They are more subtle than those of the app, but still clearly visible.
So, what's going on?
I realize that the most obvious answer is to check my graphics card drivers, and I will try downgrading to an earlier release; but meanwhile note that my fairly large for one man-project works flawlessly, and it even uses DirectX shaders! And that I've installed the latest drivers just the week before, when I also reinstalled Windows.
I'm running Windows Server 2008 R2 with all patches, and vanilla Visual Studio with SP1 - no experimental compilers, or anything.
EDIT
The problem only happens on my machine, if I compile on my machine and run on another the problem is not evident.
The XAML of the bran new project is simply:
<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>
</Grid>
</Window>
EDIT 2
It seems that there's some kind of problem with the Latest Catalyst Driver - 11.8. Installing 11.7 fixed the issue as a workaround, as, well, expected. Mystery kinda solved, except for the why...
So does anyone know why the latest catalysts cause havoc with WPF?
Looks like this is a problem with Catalyst 11.8 - see:
http://forums.amd.com/game/messageview.cfm?catid=279&threadid=154834&enterthread=y
and
WPF: can't resize window without horrible visual effects
I notice it in VS 2010 as well as our own WPF apps. It's pretty horrible. Seems as though rolling back to Catalyst 11.7 fixes the problem.
It is probably a hardware problem with your graphics card.
I am using a base Window class in a WPF project. In the code behind C# file the assembly to the base type is referenced and fine. In the XAML is looks like this:
<MyNamespace:WindowBase x:Class="MyNamespace.Applications.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNamespace="clr-namespace:MyNamespace.Somewhere;assembly=MyNamespace.Common"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
The solution compiles fine and I can run it. I just can't use the designer in VS 2010. It throws the following exception: The type'MyNameSpace:WindowBase' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well. they have been. I can't understand what this issue is. This particular base class is used in other projects just fine. I grabbed it for a new project and I can't use the designer. Very frustrating.
Found this problem just recently (this answer upgraded from a comment).
If you copy the dll from a network path, you must right click on the file in Windows Explorer, select Properties, then 'unblock'; there is a hidden NTFS stream associated with the file, and many files when you download from the 'net or copy from a network path, for security reasons.
Only the designer complains, yet the project builds and runs fine: weird isn't it?!
Whenever the designer is acting up against me - the first thing I do is clear the obj-folders in the project and rebuild. Sometimes they seem to go out of sync for some reason (usually when I'm drag-dropping a lot of files and renaming visual items).
I dont't know if its the same issue but in VS2008 I tried to make abstract UserControls but had to change this because the designer didnt't support any abstract base classes (however the solution was compilable and also worked as excpected).
Fixed. The library that contained my base class resided on a drive on the network that I did not have permissions to. That seemed to have no affect on VS 2008 as it worked, but VS 2010 apparently took exception to that when the designer tried to load it. Weird.