1 Replies - 2346 Views - Last Post: 10 March 2009 - 09:33 AM Rate Topic: -----

#1 tuxmeister  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 36
  • Joined: 25-June 08

WPF VB.net project not building.

Posted 10 March 2009 - 09:23 AM

Hey guys, I'm trying to build a little example in WPF/VB.net and I'm getting an error while trying to do so.

Here's my Window1.xaml code that defines the look of the window (the button object is a static resource defined in the App.xaml file, and only contains the look and feel of the button, nothing more):

	Width="300" Height="100" Background="{x:Null}" AllowsTransparency="True" WindowStyle="None" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
		<Storyboard x:Key="ServiceOn">
			<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
				<SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFF0000"/>
				<SplineColorKeyFrame KeyTime="00:00:01" Value="#FF00FF01"/>
			<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Offset)">
				<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
				<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
		<Storyboard x:Key="ServiceOff">
			<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="ellipse">
				<SplineColorKeyFrame KeyTime="00:00:00" Value="#FF00FF01"/>
				<SplineColorKeyFrame KeyTime="00:00:01" Value="#FFFF0000"/>
			<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="ellipse">
				<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
				<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>

	<Grid x:Name="LayoutRoot">
		<Button FontSize="30" FontWeight="Bold" Foreground="#FF2EB2D0" Style="{DynamicResource DarkGlassButton}" Content="Start" Name="Button1"/>
		<Ellipse d:LayoutOverrides="HorizontalAlignment" HorizontalAlignment="Right" Margin="0,18.833,31.334,18.5" Width="62.667" Fill="{x:Null}" StrokeThickness="5">
					<GradientStop Color="#FF000000" Offset="1"/>
					<GradientStop Color="#FFFFFFFF" Offset="0.522"/>
					<GradientStop Color="#FF000000" Offset="0"/>
		<Ellipse HorizontalAlignment="Right" Margin="0,25.125,37.875,24.875" Width="50" Height="50" Stroke="{x:Null}" x:Name="ellipse">
					<GradientStop Color="#FF000000" Offset="1"/>
					<GradientStop Color="#FFFF0000" Offset="0"/>

And here's my Window1.xaml.vb code which is the work code of the app. This would trigger an animation affecting properties of Button1 object, depending on the status of the service controll, which reads it off the "Spooler" service. The service controller has been referenced manually in the project.

Imports System
Imports System.IO
Improts System.Threading
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports System.ServiceProcess
Partial Public Class Window1
	Public Sub New()


		' Insert code required on object creation below this point.
	End Sub
	Dim sController As New ServiceController("spooler")
	Dim Thread1 As System.Threading.Thread
	Dim ServiceStatusOn As Storyboard = DirectCast(FindResource("ServiceOn"), Storyboard)
	Dim ServiceStatusOff As Storyboard = DirectCast(FindResource("ServiceOff"), Storyboard)
	Private Sub StatusCheckThread()
		If sController.Status = ServiceControllerStatus.Running Then
			Me.Button1.Content = "Stop"
		ElseIf sController.Status = ServiceControllerStatus.Stopped Then
			Me.Button1.Content = "Start"
		End If
	End Sub
	Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
		Dim Thread1 As New System.Threading.Thread(AddressOf StatusCheckThread)
	End Sub
End Class

And here's the error that I'm getting:


Cannot create instance of 'Window1' defined in assembly 'ServiceControl, Version=, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'ServiceControl;component/Window1.xaml' Line 2 Position 2.

Any ideas why would it give that error? I can't find any problems with the code in the specified file "Window1.xaml".

Thanks in advance for the help!

This post has been edited by tuxmeister: 10 March 2009 - 09:31 AM

Is This A Good Question/Topic? 0
  • +

Replies To: WPF VB.net project not building.

#2 tuxmeister  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 36
  • Joined: 25-June 08

Re: WPF VB.net project not building.

Posted 10 March 2009 - 09:33 AM

I actually figured it out. I changed the following:

Dim ServiceStatusOn As Storyboard = DirectCast(FindResource("ServiceOn"), Storyboard)

with this;

Dim ServiceStatusOn As Storyboard = DirectCast(FindName("ServiceOn"), Storyboard)

and added the "Name" property to both storyboards in the xaml file. Now the app builds and displays. In case anybody finds this useful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1