What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

[Development] WPF fails?

sinterlkaas

New Member
Joined
Jan 17, 2012
Messages
536
Reaction score
14
When using WPF the bot fails to compile the sources for a plugin

[12:40:10.296 N] Compiler Error: g:\db\Plugins\Test\Window1.xaml.cs(23,13) : error CS0103: The name 'InitializeComponent' does not exist in the current context

but when building with VS2010 it build without any errors

Searched google for this problem and found some things but still does not fix it for DB

first thing I found and tried was: found here
<Import Project=?..
It?s near the end of the file. and the only line that you have is probably this:
<Import Project=?$(MSBuildBinPath)\Microsoft.CSharp.targets? />
This tells Visual Studio to build the project as a .NET 2.0 project. What we want to do is to tell Visual Studio that this is actually a WPF project, so we have to add the following line:
<Import Project=?$(MSBuildBinPath)\Microsoft.WinFX.targets? />
This line will tell Visual Studio to build the project as a WPF project. Now your .csproj file bottom should look like this:
< Import Project=?$(MSBuildBinPath)\Microsoft.CSharp.targets? />
<Import Project=?$(MSBuildBinPath)\Microsoft.WinFX.targets? />
Save the .csproj file, right click it in the solution explorer and select ?Reload Project? Compile and that?s it, your all done!
Amit
what I did was edit the .csproj file and include it in the plugins folder with db (I dont think DB uses this file because it did not change anything)

Next I found this: found here/

The initializeComponent routine is created in the .g.cs file that is created during build. (see obj\debug\...)

Make sure your XAML file has a build action of "Page" to create that file.

Also, make sure that the partial classes in .xaml.cs and .g.cs match.

What I did is build the profject with VS2010 and copied obj\debug\Window1.g.cs to the plugins folder and opened it to correct all paths
than start DB and that results in a crash when it tries to compile the plugins without any more info in logs :(

Conclusion I am stuck and need help :)

included the VS project and the plugin as I tested it with DB
 
Last edited:
I tried to remove initialize component and add the things it does to initialize by hand but without success


Code:
Uri path = new Uri("pack://application:,,,/Window1.xaml", UriKind.Absolute);
Application.LoadComponent(path);

also changed path to just a local file in root of the drive to be sure it could find it but no success :(
 
Ok I can load content in DisplayWindow that actually does something when I click the config button

but I can not do anything with DisplayWindow because it can only use get ?

so it is not possible to make a close button or change its height and width or anything else
does this have a reason ?



Code:
<UserControl 
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid Height="260" Width="278">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="78,120,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    </Grid>
</UserControl>
Code:
        private static string configPath = string.Format("{0}\\Plugins\\Test\\Test.xaml", Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
        private Button closeButton, saveButton, defaultButton;
        public Window DisplayWindow
        {
            get
            {
                Window w = new Window();
                if (!File.Exists(configPath))
                    Log("ERROR: Can't find \"" + configPath + "\"");
                try
                {

                    StreamReader xamlStream = new StreamReader(configPath);
                    DependencyObject xamlContent = System.Windows.Markup.XamlReader.Load(xamlStream.BaseStream) as DependencyObject;

                    closeButton = LogicalTreeHelper.FindLogicalNode(xamlContent, "button1") as Button;
                    closeButton.Click += new RoutedEventHandler(Button_Click);
                    w.Content = xamlContent;
                }
                catch (System.Windows.Markup.XamlParseException ex)
                {
                    // You can get specific error information like LineNumber from the exception
                    Log(ex.ToString(), LogLevel.Diagnostic);
                }
                catch (Exception ex)
                {
                    // Some other error
                    Log(ex.ToString(), LogLevel.Diagnostic);
                }
                
                return w;
            }
            
        }
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            DisplayWindow.Close();
        }

when changing usercontrol to window in the xaml file results in a error
Code:
System.InvalidOperationException: Window must be the root of the tree. Cannot add Window as a child of Visual.
   at System.Windows.Window.OnAncestorChanged()
   at System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
   at System.Windows.TreeWalkHelper.OnAncestorChanged(DependencyObject d, TreeChangeInfo info)
   at System.Windows.DescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   at MS.Internal.PrePostDescendentsWalker`1.StartWalk(DependencyObject startNode, Boolean skipStartNode)
   at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
   at System.Windows.Window.OnContentChanged(Object oldContent, Object newContent)
   at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.Controls.ContentControl.set_Content(Object value)
   at BadProfileBehaviorFix.FixMe.get_DisplayWindow()
 
Back
Top