Error: does not contain a definition for ....
Posted: 24 Feb 2018, 19:03
I'am learning at the moment wpf and try to test things in Unity3D.
But at the Moment I hit a wall.
Unity keeps yelling at me:
I really get a headache. Where does compile when, was ?
I try to compare with the samples, but that don't help.
Sorry then this is a noob question.
UPDATE:
Tried it with this complicated mvvm, but the List never updates.
And after some time Unity yells at me, that Button_Click is not defined, but this is defined in the class and it has worked 1min before.
What a buggy mess. Sorry, get really frustrated right now.
But at the Moment I hit a wall.
Unity keeps yelling at me:
In Visual Studio, it finds List1 without problems, but Noesis Unity don't.Assets/MyResources/UI/UserControl1.xaml.cs(26,18): error CS1061: Type `UI.UserControl1' does not contain a definition for `List1' and no extension method `List1' of type `UI.UserControl1' could be found. Are you missing an assembly reference?
Code: Select all
this.List1.Items.Add("Test");Code: Select all
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System;
using System.Windows;
using System.Windows.Controls;
#endif
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace UI
{
/// <summary>
/// Interaktionslogik für UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
collection = new ItemCollection();
this.DataContext = collection;
this.Initialized += UserControl1_Initialized;
this.InitializeComponent();
}
ItemCollection collection;
public class ItemCollection : NotifyPropertyChangedBase
{
ObservableCollection<string> items;
public ObservableCollection<string> Items
{
get
{
if(items == null) items = new ObservableCollection<string> { "One", "Two", "Three" };
return items;
}
}
public void addItem(string text)
{
items.Add(text);
OnPropertyChanged("Items");
}
}
public void UserControl1_Initialized(object sender, EventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
collection.addItem("TestBBB");
}
#if NOESIS
void InitializeComponent()
{
Noesis.GUI.LoadComponent(this, "Assets/MyResources/UI/UserControl1.xaml");
}
#endif
}
}
Code: Select all
<UserControl x:Class="UI.UserControl1"
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"
xmlns:local="clr-namespace:UI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Background="#FF2B6EA8"
>
<Border Padding="10">
<StackPanel>
<Button Content="Test" Click="Button_Click" />
<ListView x:Name="List1" Background="Transparent" Height="200" ItemsSource="{Binding Items}">
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Margin="0 0 0 2" Background="Wheat"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
</ListView>
</StackPanel>
</Border>
</UserControl>
I try to compare with the samples, but that don't help.
Sorry then this is a noob question.
UPDATE:
Tried it with this complicated mvvm, but the List never updates.
And after some time Unity yells at me, that Button_Click is not defined, but this is defined in the class and it has worked 1min before.
What a buggy mess. Sorry, get really frustrated right now.