danrer
Topic Author
Posts: 10
Joined: 27 Apr 2019, 18:20

Not work binding

05 May 2020, 17:34

I can't understand why I don't have some BINDING elements working, when loading it gets an element and takes all the necessary information from it, but then it stops responding to SelectedResearch changes.

Although it is changing, this can be seen from the progress of the bars.

Does not work
        <TextBlock HorizontalAlignment="Left" Margin="391,41,0,0" TextWrapping="Wrap" Text="{Binding SelectedResearch.Name}" VerticalAlignment="Top" Height="100" Width="443" FontSize="24"/>
        <Image Source="{Binding SelectedResearch.Icon, Converter={StaticResource Texture2DToTextureSourceConverter}}" HorizontalAlignment="Left" Height="100" Margin="286,41,0,0" VerticalAlignment="Top" Width="100"/>
        <TextBlock HorizontalAlignment="Left" Margin="286,148,0,0" TextWrapping="Wrap" Text="{Binding SelectedResearch.Description}" VerticalAlignment="Top" Width="548" Height="127"/>
        <ListBox
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemContainerStyle="{StaticResource QueueRequirementItemStyle}"
            ItemsSource="{Binding SelectedResearch.Requirements}" Margin="286,280,293,10"/>
        <ListBox
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemContainerStyle="{StaticResource QueueRequirementItemStyle}"
            ItemsSource="{Binding SelectedResearch.Cost}" Margin="606,280,10,10"/>
XAML
<UserControl x:Class="UI.ResearchWindow.ResearchWindow"
             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="UI.ResearchWindow"
             mc:Ignorable="d" 
             Height="450" Width="894" Background="#FF464646">
    <UserControl.Resources>
        <ResourceDictionary Source="../Resources/Resources.xaml"/>
    </UserControl.Resources>
    <Grid Background="#FF404040">
        <Label Content="Header" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="780" FontSize="16" FontWeight="Bold"/>
        <Label Content="Number of scientists" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top" Width="227" FontSize="16" FontWeight="Bold"/>
        <TabControl HorizontalAlignment="Left" Height="325" Margin="10,77,0,0" VerticalAlignment="Top" Width="271">
            <TabItem Header="Available" FontFamily="Arial">
                <Grid Background="#FFE5E5E5">
                    <ListBox
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemContainerStyle="{StaticResource QueueItemStyle}"
                        ItemsSource="{Binding AvailableForResearch}"
                        SelectedItem="{Binding SelectedResearch}"/>
                </Grid>
            </TabItem>
            <TabItem Header="Not Available">
                <Grid Background="#FFE5E5E5">
                    <ListBox
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemContainerStyle="{StaticResource QueueItemStyle}"
                        ItemsSource="{Binding NotAvailableForResearch}"
                        SelectedItem="{Binding SelectedResearch}"/>
                </Grid>
            </TabItem>
            <TabItem Header="Completed">
                <Grid Background="#FFE5E5E5">
                    <ListBox
                        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                        ItemContainerStyle="{StaticResource QueueItemStyle}"
                        ItemsSource="{Binding CompletedResearch}"
                        SelectedItem="{Binding SelectedResearch}"/>
                </Grid>
            </TabItem>
        </TabControl>

        <!--Does not work-->
        <TextBlock HorizontalAlignment="Left" Margin="391,41,0,0" TextWrapping="Wrap" Text="{Binding SelectedResearch.Name}" VerticalAlignment="Top" Height="100" Width="443" FontSize="24"/>
        <Image Source="{Binding SelectedResearch.Icon, Converter={StaticResource Texture2DToTextureSourceConverter}}" HorizontalAlignment="Left" Height="100" Margin="286,41,0,0" VerticalAlignment="Top" Width="100"/>
        <TextBlock HorizontalAlignment="Left" Margin="286,148,0,0" TextWrapping="Wrap" Text="{Binding SelectedResearch.Description}" VerticalAlignment="Top" Width="548" Height="127"/>
        <ListBox
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemContainerStyle="{StaticResource QueueRequirementItemStyle}"
            ItemsSource="{Binding SelectedResearch.Requirements}" Margin="286,280,293,10"/>
        <ListBox
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemContainerStyle="{StaticResource QueueRequirementItemStyle}"
            ItemsSource="{Binding SelectedResearch.Cost}" Margin="606,280,10,10"/>
        <!--END-->
        
        <Button Content="Start research" Command="{Binding StartResearch}" HorizontalAlignment="Left" Margin="10,407,0,0" VerticalAlignment="Top" Width="271" Height="33"/>
    </Grid>
</UserControl>
XAML.cs
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
using System;
using System.Reflection;
using UnityEngine;
#else
using System;
using System.Windows;
using System.Windows.Controls;
#endif

namespace UI.ResearchWindow
{
    public partial class ResearchWindow : UserControl
    {
        public ResearchWindow()
        {
            InitializeComponent();
#if NOESIS
            DataContext = new ViewModel();
            Managers.Managers.UI.RegisterControl("ResearchWindow", this);
#endif
        }

#if NOESIS
        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "Assets/UI/ResearchWindow/ResearchWindow.xaml");
        }
#endif
    }
}
ViewModel
using BaseObjects;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UI.ResearchWindow
{
    public class ViewModel : NotifierUI
    {
        public ObservableCollection<BaseObjectResearch> CompletedResearch { get; private set; }

        public ObservableCollection<BaseObjectResearch> AvailableForResearch { get; private set; }

        public ObservableCollection<BaseObjectResearch> NotAvailableForResearch { get; private set; }

        public DelegateCommand StartResearch { get; private set; }

        public ViewModel()
        {
            CompletedResearch = Managers.Managers.Research.CompletedResearch;
            AvailableForResearch = Managers.Managers.Research.AvailableForResearch;
            NotAvailableForResearch = Managers.Managers.Research.NotAvailableForResearch;
            SelectedResearch = AvailableForResearch.FirstOrDefault();
            StartResearch = new DelegateCommand(OnStartResearch);
        }

        private BaseObjectResearch _selectedResearch;
        public BaseObjectResearch SelectedResearch
        {
            get
            {
                return _selectedResearch;
            }
            set
            {
                if (_selectedResearch != value)
                {
                    _selectedResearch = value;
                    OnPropertyChanged();
                }
            }
        }

        private void OnStartResearch(object param)
        {
            Managers.Managers.Research.StartResearch(SelectedResearch);
        }
    }
}
Noesis 2.2.6
Attachments
Screenshot_6.png
Screenshot_5.png
 
danrer
Topic Author
Posts: 10
Joined: 27 Apr 2019, 18:20

Re: Not work binding

05 May 2020, 18:22

Sorry, I'm a fool, I forgot to add INotifyPropertyChanged, you can delete this topic.
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Not work binding

05 May 2020, 18:33

Thanks for the feedback! Closing this

Who is online

Users browsing this forum: No registered users and 1 guest