User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

[Unity] TabControl using ItemsSource throws exception

20 Sep 2014, 20:49

As the subject says, I'm just trying to populate a TabControl with items by binding a Collection to the ItemsSource. Doing so results in the following exception:
{{{
Unhandled exception at 0x24471409: Access Violation reading location 0x8E3F1AA0
}}}
{{{
[ 0] [0x24471409] Noesis.dll!Noesis::Gui::DependencyPropertyChangedEventArgs::GetClassType + 0xc9 bytes
[ 1] [0x24471B4C] Noesis.dll!Noesis::Gui::DependencyObject::InternalGetValue + 0x1c bytes
[ 2] [0x244CBB19] Noesis.dll!Noesis::Gui::BaseTextBox::UpdateVisualStates + 0x5299 bytes
[ 3] [0x245E5649] Noesis.dll!Noesis::Gui::TabItem::SetIsSelected + 0x29 bytes
[ 4] [0x245E504A] Noesis.dll!Noesis::Gui::TabControl::OnSelectionChanged + 0x3a bytes
[ 5] [0x245D21E8] Noesis.dll!Noesis::Gui::Selector::ManageSingleSelectionChanged + 0x1b8 bytes
[ 6] [0x245D271E] Noesis.dll!Noesis::Gui::Selector::OnPropertyChanged + 0x3e bytes
[ 7] [0x24597069] Noesis.dll!Noesis::Gui::Popup::StaticOnPopupLostMouseCapture + 0xad9 bytes
[ 8] [0x244CBFCF] Noesis.dll!Noesis::Gui::BaseTextBox::UpdateVisualStates + 0x574f bytes
[ 9] [0x245D1DB9] Noesis.dll!Noesis::Gui::Selector::SetSelectedIndex + 0x29 bytes
[10] [0x245E3FDE] Noesis.dll!Noesis::Gui::TabControl::OnItemsChanged + 0x2e bytes
[11] [0x24557591] Noesis.dll!Noesis::Gui::ItemsControl::OnItemsChangedInternal + 0x11 bytes
[12] [0x24556666] Noesis.dll!Noesis::Gui::ItemCollection::OnCollectionChanged + 0x16 bytes
[13] [0x244E53F1] Noesis.dll!Noesis::Gui::CollectionView::InternalCollectionChanged + 0x21 bytes
[14] [0x244E4A19] Noesis.dll!Noesis::Gui::Collection::Add + 0xa9 bytes
[15] [0x24713309] Noesis.dll!Collection_Add__SWIG_0 + 0x59 bytes
[16] [0x1BAEAA69]
[17] [0x0BC003FC] mono.dll!mono_gc_wbarrier_arrayref_copy + 0x26f9 bytes
[18] [0x0BAF1D44] mono.dll!g_free + 0x316 bytes
}}}
Xaml:
<TabControl ItemsSource="{Binding Tabs2}" />
Code UserControl:
		Collection _tabs2;
		public Collection Tabs2
		{
			get { return _tabs2; }
			set
			{
				if (value != _tabs2)
				{
					_tabs2 = value;
					NotifyPropertyChanged("Tabs2");
				}
			}
		}

		public override void OnPostInit()
		{
			base.OnPostInit();

			Tabs2 = new Collection();

			Tabs2.Add(new TestTabItem() { Header = "Test 1" });
			Tabs2.Add(new TestTabItem() { Header = "Test 2" });
		}
Code TestTabItem:
	[Extended]
	public class TestTabItem : BaseComponent
	{
		string _header;
		public string Header
		{
			get { return _header; }
			set
			{
				if (value != _header)
				{
					_header = value;
					NotifyPropertyChanged("Header");
				}
			}
		}
	}
Am I doing anything wrong or is this a bug?
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] TabControl using ItemsSource throws exception

23 Sep 2014, 11:50

There is a bug, we will fix it for the next release :oops:
Sorry for the inconvenience.

Meanwhile you will have to create the TabItems yourself and add them to the TabControl in code :(
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] TabControl using ItemsSource throws exception

25 Sep 2014, 22:52

I tried adding the TabItems in code but I'm just not able to add (or see?) any content. I tried various different things, overwriting Templates and Styles, setting them in XAML and code, it just doesn't work.

So my current workaround is an ugly mess of setting the TabItems in XAML and retrieving the child elements in code. It would be nice to either confirm it as a bug or tell me how to do it.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] TabControl using ItemsSource throws exception

29 Sep 2014, 16:40

What I meant was to add the TabItems to the TabControl.Items property in code. Something like this is working for me:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TabControl x:Name="Tabs" Width="200" Height="200"/>
    <Button x:Name="btn" Content="Add Tabs" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="10"/>
</Grid>
public class Test : MonoBehaviour
{
    TabControl _tabs;

    void Start()
    {
        var gui = GetComponent<NoesisGUIPanel>();
        var root = gui.GetRoot<Grid>();

        var btn = root.FindName<Button>("btn");
        btn.Click += btn_Click;

        _tabs = root.FindName<TabControl>("Tabs");
    }

    void btn_Click(BaseComponent sender, RoutedEventArgs e)
    {
        _tabs.GetItems().Clear();

        _tabs.GetItems().Add(CreateTab(Colors.Red(), "Red", "Tab 1 Content"));
        _tabs.GetItems().Add(CreateTab(Colors.Green(), "Green", "Tab 2 Content"));
        _tabs.GetItems().Add(CreateTab(Colors.Blue(), "Blue", "Tab 3 Content"));
    }

    TabItem CreateTab(Noesis.Color color, string header, string content)
    {
        Rectangle icon = new Rectangle();
        icon.SetWidth(4.0f);
        icon.SetFill(new SolidColorBrush(color));

        TextBlock txt = new TextBlock(header);
        txt.SetMargin(new Thickness(4.0f, 0.0f, 4.0f, 0.0f));

        StackPanel panel = new StackPanel();
        panel.SetOrientation(Orientation.Horizontal);

        panel.GetChildren().Add(icon);
        panel.GetChildren().Add(txt);

        TabItem tab = new TabItem();
        tab.SetHeader(panel);
        tab.SetContent(content);

        return tab;
    }
}
You can also use a ContentControl to specify the Header and assign a Style+Template to simplify the code.
And the TabItem.Content can be whatever: a simple string, a UserControl or a loaded xaml file.
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] TabControl using ItemsSource throws exception

17 Oct 2014, 03:48

Hi, I thought using the ItemsSource would work now but unfortunately that isn't the case. :(
{{{
Unhandled exception at 0x27FBFF0F: Access Violation reading location 0x00000018
}}}
{{{
[ 0] [0x27FBFF0F] Noesis.dll!Noesis::Gui::IconSource::IconSource + 0x7f bytes
[ 1] [0x27EE221C] Noesis.dll!Noesis::Gui::DependencyObject::InternalGetValue + 0x1c bytes
[ 2] [0x27F3C189] Noesis.dll!Noesis::Gui::BaseTextBox::UpdateVisualStates + 0x5249 bytes
[ 3] [0x28057479] Noesis.dll!Noesis::Gui::TabItem::SetIsSelected + 0x29 bytes
[ 4] [0x28056F00] Noesis.dll!Noesis::Gui::TabControl::OnSelectionChanged + 0x50 bytes
[ 5] [0x280445F8] Noesis.dll!Noesis::Gui::Selector::ManageSingleSelectionChanged + 0x1b8 bytes
[ 6] [0x28044B2E] Noesis.dll!Noesis::Gui::Selector::OnPropertyChanged + 0x3e bytes
[ 7] [0x280A1B99] Noesis.dll!Noesis::Gui::Geometry::StrokeContainsOverride + 0x309 bytes
[ 8] [0x27F3C5BF] Noesis.dll!Noesis::Gui::BaseTextBox::UpdateVisualStates + 0x567f bytes
[ 9] [0x280441C9] Noesis.dll!Noesis::Gui::Selector::SetSelectedIndex + 0x29 bytes
[10] [0x28055E0E] Noesis.dll!Noesis::Gui::TabControl::OnItemsChanged + 0x2e bytes
[11] [0x27FC9731] Noesis.dll!Noesis::Gui::ItemsControl::OnItemsChangedInternal + 0x11 bytes
[12] [0x27FC87E6] Noesis.dll!Noesis::Gui::ItemCollection::OnCollectionChanged + 0x16 bytes
[13] [0x27F55BD1] Noesis.dll!Noesis::Gui::CollectionView::InternalCollectionChanged + 0x21 bytes
[14] [0x27F55199] Noesis.dll!Noesis::Gui::Collection::Add + 0xa9 bytes
[15] [0x28188F99] Noesis.dll!Collection_Add__SWIG_0 + 0x59 bytes
[16] [0x2472E769]
[17] [0x25670FCA]
[18] [0x25670F0B]
[19] [0x25682C55]
[20] [0x256828FB]
[21] [0x0BA01E35] mono.dll!g_free + 0x407 bytes
[22] [0x0BA01DDD] mono.dll!g_free + 0x3af bytes
}}}
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: [Unity] TabControl using ItemsSource throws exception

17 Oct 2014, 12:47

It's being investigated, thanks for your report.

Who is online

Users browsing this forum: Google [Bot] and 1 guest