3

I'm having the following exception: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll I looked for it and have found this thread here

Apparently the CTRL+ALT+E method and checking all the exceptions didn't solve my problem - or I used it incorrectly. I checked all the exceptions and it lead me to the InitializedComponent() function of my MainWindow and that was it. Any ideas? I'm sending all my XAML code: MainWindow

<Window x:Class="DPCKOU_prog3hf_pong.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:DPCKOU_prog3hf_pong"
    mc:Ignorable="d"
    Title="PongGame" Height="406" Width="717"
    Loaded="Window_Loaded"
    KeyDown="Window_KeyDown"
    >
<Canvas Background="{StaticResource fieldBGSP}">
    <Rectangle Canvas.Left="{Binding Path=Pad.Area.X}"
                   Canvas.Top="{Binding Path=Pad.Area.Y}"
                   Width="{Binding Path=Pad.Area.Width}"
                   Height="{Binding Path=Pad.Area.Height}"
                   Fill="{StaticResource RectangleFill}"/>
    <Ellipse Canvas.Left="{Binding Path=Ball.Area.X}"
                   Canvas.Top="{Binding Path=Ball.Area.Y}"
                   Width="{Binding Path=Ball.Area.Width}"
                   Height="{Binding Path=Ball.Area.Height}"
                   Fill="{StaticResource EllipseFill}"/>
    </Canvas>
</Window>

and my App.xaml:

<Application x:Class="DPCKOU_prog3hf_pong.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:DPCKOU_prog3hf_pong"
         xmlns:sys="clr-namespace:System;assembly=mscorlib"
         StartupUri="MainWindow.xaml">
    <Application.Resources>
        <SolidColorBrush x:Key="RectangleFill" Color="#FF0F4228"/>
        <SolidColorBrush x:Key="EllipseFill" Color="#FF207CBB"/>
          <ImageBrush x:Key="fieldBGMP" ImageSource="pack://application:,,,/texturesExport/background.png"/>
        <ImageBrush x:Key="fieldBGSP" ImageSource="pack://application:,,,/texturesExport/pong_ingameSP.png"/>
    </Application.Resources>
</Application>

Edit

I get the error at the lone > sign just before Canvas. In the editor the background image shows up just fine. No clue what could cause the issue.

I updated my code with the pack uri method.

halfer
  • 19,824
  • 17
  • 99
  • 186
agiro
  • 2,018
  • 2
  • 30
  • 62
  • 1
    please provide us with the inner exception if exists, this could very helpful to solve the problem – Hakan Fıstık Oct 30 '16 at 11:23
  • try to remove the space from the end of the `Background` property like this `` – Hakan Fıstık Oct 30 '16 at 11:25
  • I did remove them, no difference. I will update the post of course. I'm currently checking inline how to get those inner exceptions but all I find is how to get them by code :/ – agiro Oct 30 '16 at 11:27

2 Answers2

2

Are the images' build actions set to resource? Also you may try using pack uri for image sources, in this case it would be pack://application:,,,/texturesExport/background.png

czubehead
  • 552
  • 1
  • 5
  • 15
  • I used `pack uri` like this: `` and unfortunately it doesn't work. Shall I use `Image` instead of `ImageBrush`? EDIT: the location of my images in the project are: `C:\Users\agoston\Documents\Visual Studio 2015\Projects\DPCKOU_prog3hf_pong\DPCKOU_prog3hf_pong\texturesExport` – agiro Oct 30 '16 at 11:33
  • No I don't think so. Could you try inlining the resource like this? ` ` – czubehead Oct 30 '16 at 11:44
  • I tried and I get the same error. The location is pointed to that `ImageBrush` by the way. – agiro Oct 30 '16 at 11:54
  • Apparently I don't think the images build actions are resource. How to do it? I don't find it online. – agiro Oct 30 '16 at 12:24
  • I found it, but I can't edit the build actions for my images. I can though for my `.cs` files :/ any ideas? – agiro Oct 30 '16 at 12:34
  • 1
    Apparently including the image in the project did solve the build action issue and it solved my original issue, thank you. – agiro Oct 30 '16 at 12:57
1

Provided that you have no code in the *.xaml.cs file, the issue probably has to do with properly evaluating the ImageSource properties.

Comment out both ImageBrushes and see if that causes the exceptions to disappear.

Here's a solution for your issue

Community
  • 1
  • 1
Eyal Perry
  • 2,255
  • 18
  • 26
  • Thanks for the input. Now that i removed my `ImageBrushes` and the `Background` property of the `Canvas` I get a `LoadFromContext error`. I used to be find by the way. I do have code in my `MainWindow.cs` and my other classes but before adding the `ImageBrushes` they worked fine. EDIT: by the way after that `error` I hist continue and it is fine. Checking what you linked.... – agiro Oct 30 '16 at 11:21
  • Another update: I used `pack ui` and it unfortunately doesn't work. I can start, so no underlines or whatnots, but I get the same `exception`. I have my images in the following folder by the way: `C:\Users\agoston\Documents\Visual Studio 2015\Projects\DPCKOU_prog3hf_pong\DPCKOU_prog3hf_pong\texturesExport` – agiro Oct 30 '16 at 11:35
  • Provide me with more code, as well as the entire exception stack (incl. inner exceptions etc) – Eyal Perry Oct 30 '16 at 11:38
  • I would rather add the whole pack if it is more convenient for you? A small example program this is. Here is the [link](https://drive.google.com/file/d/0B33RFc9jZBV5R0d5alVOTVZoVWc/view?usp=sharing) – agiro Oct 30 '16 at 11:43
  • it would be better if you posted a gist ( or a few) - or uploaded this to a github repository. I will not unzip anything onto my computer, no offense. – Eyal Perry Oct 30 '16 at 11:47
  • Fair enough. I'm messing around with BitBucket but not sure how to. trying that now... – agiro Oct 30 '16 at 11:51
  • it isn't done yet but I'm trying to set up the build actions for my `PNG` images. Apparently I have no `build actions` property for those. Any ideas? – agiro Oct 30 '16 at 12:42
  • Done, I didn't set the image to resource. All the help appreciated. – agiro Oct 30 '16 at 12:58