0

I'm attempting to add a StackPanel to a Grid on this Window, I have passed the Window to the method.

App.xaml.cs

/// <summary>
        /// Show single notifications
        /// </summary>
        /// <param name="window"></param>
        public static void showSingle(Window window)
        {
            // Find the resource, then cast it to a runtimeObject
            var runtime = (runtimeObject)Application.Current.TryFindResource("runtimeVariables");
            Style style = Application.Current.Resources["NotificationsContainer"] as Style;

            //Create container control
            StackPanel container = new StackPanel();
            container.Style = style;

            //Append to Window
            window.Container.Children.Add(container);
        }

This is the XAML of the Window:

<Window x:Class="Test_Project.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:Test_Project"
        mc:Ignorable="d"
        xmlns:Extensions="clr-namespace:Test_Project.Classes"
        xmlns:Controls="clr-namespace:Controls;assembly=Controls"
        Title="MainWindow" Height="609.925" Width="573" Name="Main">
    <Grid Name="Container">

I'm getting an error however saying:

'Window' does not contain a definition for 'Container' and no extension method 'Container' accepting a first argument of type 'Window' could be found (are you missing a using directive or an assembly reference?)

I have got a feeling i'm doing this wrong, ideas?

Martyn Ball
  • 4,679
  • 8
  • 56
  • 126

1 Answers1

1

public static void showSingle(Window window) - Window is a base class and it doesn't contain definition for Container. You should use your Window class (MainWindow).

Andrey
  • 160
  • 1
  • 9