Update. Thanks to my new friend Josh Twist (http://www.thejoyofcode.com) I found out that a hotfix by Microsoft solves this issue. Based on the articles on his website I managed to tidy up my XAML-code to. You can find information about the hotfix at http://support.microsoft.com/kb/958017/ and download it from http://code.msdn.microsoft.com/KB958017/Release/ProjectReleases.aspx?ReleaseId=1719.
In a previous post I stated that Visual Studio never crashed on me. I have to take that back since it now happens to me a lot.
I am pretty sure that it is because I’m doing all kind of things wrong in my code (I still need to learn WPF), but VS should never crash because I mistype some code. Below is a code snippet from a XAML-file that crashes VS every time. If I open up the XAML file in MS Blend, I get an error message (probably pointing into the right direction of the error):
TargetType van ControlTemplate BoardPiece komt niet overeen met sjabloontype TagVisualization.
(which is Dutch for telling me the TargetType of the ControlType doesn’t match the TemplateType TagVisualization).
Below is the contents of the XAML file. IsAcceptingNewRelation is a user defined dependency property. I specified the Oase.BoardPiece type in the TargetType of the ControlTemplate for the code to solve the IsAcceptingNewRelation dependency property of my TagVisualization. There probably is another/proper way of doing that, but I’m getting WPF blind. Anyway, this crashes VS if I take it to the design mode.
1: <s:TagVisualization
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: xmlns:s="http://schemas.microsoft.com/surface/2008"
5: xmlns:local="clr-namespace:Oase"
6: xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7: xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8: x:Class="Oase.BoardPiece"
9: mc:Ignorable="d"
10: s:Contacts.ContactDown="TagVisualization_ContactDown"
11: s:Contacts.ContactChanged="TagVisualization_ContactChanged"
12: s:Contacts.ContactUp="TagVisualization_ContactUp"
13: >
14:
15: <s:TagVisualization.Resources>
16: <ImageBrush x:Key="tvBackground" Stretch="UniformToFill" Opacity="1" ImageSource="pack://application:,,,/Resources/speelstuk.png"/>
17: <ImageBrush x:Key="tvBackgroundHighlight" Stretch="UniformToFill" Opacity="1" ImageSource="pack://application:,,,/Resources/speelstukHighlight.png"/>
18: <ImageBrush x:Key="itemHomeBackground" Stretch="UniformToFill" Opacity="1" ImageSource="pack://application:,,,/Resources/home.png"/>
19: </s:TagVisualization.Resources>
20:
21: <s:TagVisualization.Template>
22: <ControlTemplate TargetType="{x:Type local:BoardPiece}">
23: <Grid x:Name="mainGrid" Width="126" Height="142" Background="{StaticResource tvBackground}" />
24:
25: <ControlTemplate.Triggers>
26: <Trigger Property="IsAcceptingNewRelation" Value="true">
27: <Setter TargetName="mainGrid" Property="Background" Value="{StaticResource tvBackgroundHighlight}" />
28: </Trigger>
29: <Trigger Property="IsAcceptingNewRelation" Value="false">
30: <Setter TargetName="mainGrid" Property="Background" Value="{StaticResource tvBackground}" />
31: </Trigger>
32: </ControlTemplate.Triggers>
33: </ControlTemplate>
34: </s:TagVisualization.Template>
35:
36: </s:TagVisualization>
If anyone out there know how I can prevent VS from crashing (probably by pointing out what part of WPF I don’t understand here …) it’s much appreciated if you tell me :-)
Bye,
Bart
No comments:
Post a Comment