Yes, sorry, we did a few changes in the last version and the C# documentation is not yet updated (and also the samples for that part, we are working on it). The correct signature is (same as in C++):
protected virtual bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Click" && handlerName == "OnButtonClick")
{
((Button)source).Click += this.OnButtonClick;
return true;
}
return false;
}
Thanks that got rid of the error but now I get another one instead:
'SpaceGui.Assets.Gui.InventoryGrid' does not contain a definition for 'OnButtonClick'
I'm not too familiar with this framework yet so I'm probably doing something wrong so I posted the code that throws the error below below.
#if UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_WINRT_8_1
#define UNITY
#endif
#if UNITY
using Noesis;
using UnityEngine;
#else
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
#endif
using System.Linq;
using System.Collections.ObjectModel;
using DataModels;
namespace SpaceGui.Assets.Gui
{
/// <summary>
/// Interaction logic for InventoryGrid.xaml
/// </summary>
public partial class InventoryGrid : UserControl
{
ObservableCollection<InventoryContentDto> _items;
GameUiDataModel _model;
public InventoryGrid()
{
this.Initialized += OnInitialized;
InitializeComponent();
}
#if UNITY
void InitializeComponent()
{
Noesis.GUI.LoadComponent(this, "Assets/Gui/InventoryGrid/InventoryGrid.xaml");
}
#endif
private void OnInitialized(object sender, EventArgs e)
{
#if UNITY
GameManager.Instance.RegisterUI(this);
#endif
}
public void SetInventory(ObservableCollection<InventoryContentDto> items)
{
_items = items;
_model = new GameUiDataModel(_items);
this.DataContext = _model;
}
public Visibility IsInventoryVisible
{
get { return _model.IsInventoryVisible; }
set { _model.IsInventoryVisible = value; }
}
protected virtual bool ConnectEvent(object source, string eventName, string handlerName)
{
#if UNITY
Debug.Log("Connecting Events");
#endif
if (eventName == "Click" && handlerName == "OnButtonClick")
{
((Button)source).Click += this.OnButtonClick;
return true;
}
return false;
}
public void OnButtonClick(object sender, RoutedEventArgs args)
{
var btn = (Button)sender;
#if UNITY
Debug.Log("Button was clicked"+btn.Name);
#endif
System.Console.WriteLine("Button was clicked");
}
}
}
<UserControl x:Class="SpaceGui.Assets.Gui.InventoryGrid"
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:SpaceGui.Assets.Gui.InventoryGrid"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Width="Auto">
<UserControl.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="5,4,25,4"/>
</Style>
<Style x:Key="HeaderRight">
<Setter Property="GridViewColumnHeader.HorizontalContentAlignment" Value="Right"/>
<Setter Property="GridViewColumnHeader.Padding" Value="10,0"/>
</Style>
</UserControl.Resources>
<DockPanel LastChildFill="True" Visibility="{Binding IsInventoryVisible}">
<Label TextElement.FontFamily="../Fonts/#Source Sans Pro" TextElement.FontSize="20" TextElement.FontWeight="Bold" DockPanel.Dock="Top" Content="{Binding LocalInventoryText}"/>
<StackPanel DockPanel.Dock="Left">
<ListBox TextElement.FontFamily="../Fonts/#Source Sans Pro">
<ListBoxItem>All</ListBoxItem>
<ListBoxItem>Resources</ListBoxItem>
<ListBoxItem>Refined Resources</ListBoxItem>
<ListBoxItem>Crafting Material</ListBoxItem>
</ListBox>
<Button x:Name="TestBtn" Content="Test" Click="OnButtonClick"></Button>
</StackPanel>
<ListView x:Name="ListItems" ItemsSource="{Binding Items}" TextElement.FontFamily="../Fonts/#Source Sans Pro">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Item.Name}" TextAlignment="Left" Padding="5,0,25,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Weight" Width="Auto" HeaderContainerStyle="{StaticResource HeaderRight}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Item.Weight}" TextAlignment="Right" Padding="10,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Count" Width="Auto" HeaderContainerStyle="{StaticResource HeaderRight}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Count}" TextAlignment="Right" Padding="10,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="200" DisplayMemberBinding="{Binding Item.ItemType}"/>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
</UserControl>