none
Not rendering in UI RRS feed

  • Question

  • The observer doesn't update GUI. WPF.

    Is there a problem with the theards?

    <Window x:Class="SnakeWPF.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:SnakeWPF"
            mc:Ignorable="d"
            Title="MainWindow" Height="800" Width="1200">
        <StackPanel >
        <Grid x:Name="Root">
         
        </Grid>
            <Button Content="Attack" Name="ButtonAttack" Click="ATTACK_OnClick"/>
            <TextBox Name="Status" Text="Not started" TextAlignment="Center" FontWeight="Bold"></TextBox>
        </StackPanel>
    </Window>
    


    public partial class MainWindow : Window { internal Game Gm; public MainWindow() { InitializeComponent(); DasBoard dasBoard = new DasBoard(ImportFormat.ReadFile("form.txt")); Gm = new Game(dasBoard); Grid mainGrid = new Grid(); Root.Children.Add(mainGrid); mainGrid.ShowGridLines = true; var subscrib = Gm.Snake.ObserveOn(this) .Finally(() => { }) .Subscribe( n => { Status.Text = "Running"; var y = mainGrid.Children.OfType<Panel>().Where(i => Grid.GetRow(i) == n.Coordinates.Y); IEnumerable<Panel> panel = y.Where(t => Grid.GetColumn(t) == n.Coordinates.Y); panel.First().Background = new SolidColorBrush(Colors.Blue); ButtonAttack.Foreground = new SolidColorBrush(Colors.Goldenrod); ButtonAttack.Background = new SolidColorBrush(Colors.Red); ButtonAttack.Content = "running"; ButtonAttack.IsEnabled = false; Thread.Sleep(TimeSpan.FromSeconds(1)); }, e => { Status.Text = "Error"; }, () => { Status.Text = "commpled"; }); // Observable.Timer(TimeSpan.FromSeconds(1)).ObserveOn(gm.Snake).Subscribe<Watcher>(new Watcher(),null).Dispose(); for (var i = 0; i < dasBoard.MaxY; i++) { mainGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); } for (var i = 0; i < dasBoard.MaxX; i++) { mainGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); } for (short x = 0; x < dasBoard.MaxX; x++) { for (short y = 0; y < dasBoard.MaxY; y++) { Node node = dasBoard.GetNode(new Point(y, x)); StackPanel panel = new StackPanel() { Background = new SolidColorBrush(Colors.Red) }; panel.Children.Add(new Label() { Content = node != null ? node.GetCode() : null }); mainGrid.Children.Add(panel); Grid.SetRow(panel, x); Grid.SetColumn(panel, y); } } } private void ATTACK_OnClick(object sender, RoutedEventArgs e) { Gm.Go(); } /* internal class Watcher : IObserver<Node> { public void OnNext(Node value) { Thread.Sleep(TimeSpan.FromSeconds(1)); Console.WriteLine("next" + value); } public void OnError(Exception error) { throw new NotImplementedException(); } public void OnCompleted() { Console.WriteLine("joepie"); } */ public void Deconstruct(out Game gm) { gm = Gm; } } }

    Sunday, February 3, 2019 5:26 PM