I'm using Visual Studio 2015 Community and I get the following error message:
Invalid value for 'Event'-Property:
Microsoft.VisualStudio.DesignTools.Xaml.LanguageService.Semantics.XmlValue.
Here's the code behind:
<Style x:Key="TextBoxStyle1" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
<EventSetter Event="MouseEnter" Handler="Check_MouseEnter" />
<EventSetter Event="MouseLeave" Handler="Check_MouseLeave" />
<EventSetter Event="GotFocus" Handler="Check_GotFocus" />
I've tried UIElement.MouseEnter, Mouse.MouseEnter, TextBox.MouseEnter. If I compile the handler works just fine, but the error message is still there.
Any suggestions?
This seems a bug in the WPF designer, as already reported here on Microsoft Connect.
It seems that the designer falsely gives an warning or error, but eventually the code is okay, so it compiles and works. Nothing you should worry about now, since the product isn't released yet.
Finally, 7.5 years after this question, the bug is fixed since VS 2022 version 17.5 Preview 2.
On the Release channel, the fix is expected to be available from February 2023.
Related
I've got a bit of a niche scenario which I'm fully not expecting anyone to solve, but thought I'd give it a shot:
I have a Windows Forms User Control, which contains a single ElementHostcontrol that has it's Child property set to a WPF / XAML user control.
I'm getting some strange behaviour whereby the XAML contains something that looks like this:
<UserControl>
<UserControl.Resources>
<somenamespace:myresource x:Key="foo" />
</UserControl.Resources>
<Grid DataContext="{StaticResource foo}">
...
</Grid>
</UserControl>
I get a XamlParseException at runtime, asking me to Provide a value, even though it's clearly defined above.
I can see InitializeComponent() is being called, but that's as far as I can step.
In my code behind, in the WPF / XAML user control, if before InitializeComponent() is called I add:
this.Resources["foo"] = new myresource() everything works great again.
Just to confuse matters even further, this only happens when I use Visual Studio 2015 to compile the code - compiling using VS2013 (on the same machine/no solution changes whatsoever) works perfectly.
Has anyone got any ideas, or even helps on how to debug this?
This problem is pretty much the same as this one. However my problem is that I get this error but it does compile run and find it find.
My XAML with the error is a resource dictionary (in a different project) and it is trying to use an enum called MainViewMode in a style. I have inherited the code from a previous team so I do not know why it was originally written like this but the xaml consists of all the path data for icons (using the <geometry> tag) as well as all of the Styles. I don't think this is relevant to the problem but just thought I would highlight it anyway.
As I said, when the program runs it does work fine however the designer mode is not working on one of the forms I need to modify and it is making it really annoying.
xmlns:cenum="clr-namespace:ABC;assembly=DEF"
...
<Style x:Key="MainViewToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="CommandParameter" Value="{x:Static cenum:MainViewMode.Overview}" />
...
</style>
I have a resource dictionary, it calls an enum in a different project and says that it can't find it. It does however find it at runtime and work fine.
The main issue is that the designer doesn't load for any forms using this resource dictionary.
I believe your problem is that your namespace is incorrect. Take a look at the top answer in the question you linked to and notice how they have the example namespace. Since you're getting the enum from a different project you will also want to add that project as a reference.
To get the namespace right find the folder that the enum class is in, or if it's not in a folder just the project name. The namespace will be like one of the following,
If it's in a folder try something like this
ProjectName.FolderName;assembly=ProjectName
If not try something like this
ProjectName;assembly=ProjectName
At my place of work we've recently been upgrading our codebase from .Net 3.5 to .Net 4 (C#). Most issues encountered have been solved however this one I can't figure out. We initialise controls and pages through a mix of xaml and code behind (based on developer preference), however one page is throwing NullReferenceException when opened. Here is a snippet of code that is (one of many controls) throwing.
All the code throwing exceptions is inside a DataTemplate (I figured that might be relevant)
<TextBox x:Name="Values" Grid.Column="1" Grid.Row="0" Margin="5,2,5,2"
Text="{Binding ElementName=Descriptions, Path=SelectedValue, UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
Converter={StaticResource EmptyConverter}}"
GotFocus="Column_GotFocus"
MinWidth="100"
CharacterCasing="Upper"
Visibility="{Binding Path=IsValueVisible, Converter={StaticResource VisibilityConverter}}"
/>
Now in this, the line throwing is:
GotFocus="Column_GotFocus"
Column_GotFocus is in the code behind file.
A few more facts: we had no issues before the migration, the exception gets throws continuously, and there are three different events causing this issue.
The three events throwing are:
GotFocus="Column_GotFocus"
SelectionChanged="Descriptions_SelectionChanged"
Click="Search_Click"
Removing these fixes our problem completely, but obviously causes functional problems with the software. Does anyone have any idea what could be causing these issues?
EDIT:
Sorry, to clarify: The event handler is never called, the xaml event handler adding (GotFocus="Column_GotFocus" for example) seems to be where the exception is thrown.
The exception is:
System.NullReferenceException occurred
Message=Object reference not set to an instance of an object.
Source= <assembly/namespace>
StackTrace:
at <assembly/namespace>.<Class>.System.Windows.Markup.IStyleConnector.Connect(Int32 connectionId, Object target) in <XamlFilePath>:line 291
InnerException:
Edit 2:
The method handler is:
private void Column_GotFocus(object sender, RoutedEventArgs e)
{
ContentPresenter columnContentPresenter =(DependencyObject)sender).FindParent<ContentPresenter>();
Column column = (Column)columnContentPresenter.Content;
string message = string.Format("{0} ({1})", column.Name, column.Field);
ModuleDescriptor.UpdateStatusBar(message);
}
This is a framework bug and it is already fixed, please download the hot fix to overcome the issue!!
http://support.microsoft.com/kb/2464222
Bug report is here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/629bfcc5-2005-4947-a001-993524798b52
Download the file here
I think th problem is you are trying to add event handlers while you are in a style setter.
This is forbidden (for obscure reasons)...
You should use EventSetters instead
For example:
<Style x:Key="YourSyleName" TargetType="{x:Type CtrlType}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="dgClient_PreviewMouseLeftButtonDown"/>
<EventSetter Event="Loaded" Handler="GridContent_Loaded"/>
</Style>
I am beginning to learn XAML and I am following along with the MCTS Self-Paced Training book. I've come to the section about triggers (more specifically Property Triggers) and I stumbled upon something that is rather annoying.
Here is my code:
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property=""
</Style.Triggers>
</Style>
Now, when I want to get the property that Trigger points to I want Intellisense to list all the available properties and it doesn't. Is that something I'm doing, a problem with VS, or is it just not supported in that scenario. Besides this, it works when I set the Setter for the Trigger. For example:
<Setter Property="INTELLISENSE WORKS" Value="Something" />
I'd really like for the properties of the Button to show up like IsMouseOver.
Check your version of visual studio and upgrade to Visual Studio 2010 Service Pack 1 that everything should work as expected (Y).
Visual Studio 2010 (without the service pack) does not have intellisense for triggers.
I'm trying to style the header of a listview depending on hover/pressed/etc. events.
So far I tried a few things such as a trigger like the following but this does not work on my machine (a Vista Ultimate x64)
<Style x:Key="GridViewColumnHeaderStyle1" TargetType="{x:Type GridViewColumnHeader}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
And the listview code:
<ListView VerticalAlignment="Bottom" IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle1}" >
<GridViewColumn Header="abc"/>
<GridViewColumn Header="cde"/>
</GridView>
</ListView.View>
<ListView.DataContext>
<DataTemplate>
<ListViewItem Content="zxc"/>
</DataTemplate>
</ListView.DataContext>
</ListView>
The behaviour I expect is for the background of the header that I hover to become green.
Any ideas?
NT
I have reported this as a bug on Connect:
https://connect.microsoft.com/WPF/feedback/ViewFeedback.aspx?FeedbackID=475669
This is confirmed as a bug, and will not be fixed in time for .NET framework 4.0 as per the MS drone's response in Microsoft Connect.
Hooray for closed source software yet again...
Yes it does.
If it were open-source, then I would've drilled down, fixed it and provided a patch myself.
Then me and others who would use the "development" version would benefit in the mean time.
Now we don't even know when it's getting fixed, if ever. There are so many bugs that have not been fixed for years in .NET and other closed source projects.
Closed source does not allow you to do this. And this is another reason why I will strive to use open source.
Regards
NT
Just take the provided Control Template Microsoft provides and adjust it how you see fit. That's how we remove all the additional highlighting Microsoft adds per control.
You can find the templates at this link:
http://msdn.microsoft.com/en-us/library/aa970773(v=VS.100).aspx