Move controls on View from ViewModel





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to make a monopoly game using the WPF, Prism and MVVM.
On my View I have a grid divided into several rows and columns. Each cell is a separate game card, for example, a city.



I also have a content controls which displays my players as chips.



The task is to move my players, relative to the cells in the grid.
And I need to do this from my ViewModel.(I want my ViewModel tells somehow to my View where to locate player). Just help me with approach to this problem.



My View:



            <!--bottom row-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Cards[0]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="10" Grid.Column="9" Content="{Binding Cards[1]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--left column-->
<ContentControl Grid.Row="9" Grid.Column="0" Content="{Binding Cards[11]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="8" Grid.Column="0" Content="{Binding Cards[12]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--top row-->
<ContentControl Grid.Row="0" Grid.Column="0" Content="{Binding Cards[20]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--right column-->
...

<!--player chips-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Players[0]}" ContentTemplate="{StaticResource PlayerTemplate1}"/>
...


What I expect:
1)Model makes a dice roll(actually i have done this)
2)ViewModel gets this result and transform it to position on grid(have some ideas)
3)View must somehow get this position and move my player.










share|improve this question























  • You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

    – Wes
    Jan 3 at 21:43











  • My answer to this question should provide you with enough to get started.

    – Mark Feldman
    Jan 3 at 22:41











  • Thank you @MarkFeldman! Can you help another one?

    – Eugen
    Jan 4 at 19:26


















0















I am trying to make a monopoly game using the WPF, Prism and MVVM.
On my View I have a grid divided into several rows and columns. Each cell is a separate game card, for example, a city.



I also have a content controls which displays my players as chips.



The task is to move my players, relative to the cells in the grid.
And I need to do this from my ViewModel.(I want my ViewModel tells somehow to my View where to locate player). Just help me with approach to this problem.



My View:



            <!--bottom row-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Cards[0]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="10" Grid.Column="9" Content="{Binding Cards[1]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--left column-->
<ContentControl Grid.Row="9" Grid.Column="0" Content="{Binding Cards[11]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="8" Grid.Column="0" Content="{Binding Cards[12]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--top row-->
<ContentControl Grid.Row="0" Grid.Column="0" Content="{Binding Cards[20]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--right column-->
...

<!--player chips-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Players[0]}" ContentTemplate="{StaticResource PlayerTemplate1}"/>
...


What I expect:
1)Model makes a dice roll(actually i have done this)
2)ViewModel gets this result and transform it to position on grid(have some ideas)
3)View must somehow get this position and move my player.










share|improve this question























  • You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

    – Wes
    Jan 3 at 21:43











  • My answer to this question should provide you with enough to get started.

    – Mark Feldman
    Jan 3 at 22:41











  • Thank you @MarkFeldman! Can you help another one?

    – Eugen
    Jan 4 at 19:26














0












0








0








I am trying to make a monopoly game using the WPF, Prism and MVVM.
On my View I have a grid divided into several rows and columns. Each cell is a separate game card, for example, a city.



I also have a content controls which displays my players as chips.



The task is to move my players, relative to the cells in the grid.
And I need to do this from my ViewModel.(I want my ViewModel tells somehow to my View where to locate player). Just help me with approach to this problem.



My View:



            <!--bottom row-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Cards[0]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="10" Grid.Column="9" Content="{Binding Cards[1]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--left column-->
<ContentControl Grid.Row="9" Grid.Column="0" Content="{Binding Cards[11]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="8" Grid.Column="0" Content="{Binding Cards[12]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--top row-->
<ContentControl Grid.Row="0" Grid.Column="0" Content="{Binding Cards[20]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--right column-->
...

<!--player chips-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Players[0]}" ContentTemplate="{StaticResource PlayerTemplate1}"/>
...


What I expect:
1)Model makes a dice roll(actually i have done this)
2)ViewModel gets this result and transform it to position on grid(have some ideas)
3)View must somehow get this position and move my player.










share|improve this question














I am trying to make a monopoly game using the WPF, Prism and MVVM.
On my View I have a grid divided into several rows and columns. Each cell is a separate game card, for example, a city.



I also have a content controls which displays my players as chips.



The task is to move my players, relative to the cells in the grid.
And I need to do this from my ViewModel.(I want my ViewModel tells somehow to my View where to locate player). Just help me with approach to this problem.



My View:



            <!--bottom row-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Cards[0]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="10" Grid.Column="9" Content="{Binding Cards[1]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--left column-->
<ContentControl Grid.Row="9" Grid.Column="0" Content="{Binding Cards[11]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
<ContentControl Grid.Row="8" Grid.Column="0" Content="{Binding Cards[12]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--top row-->
<ContentControl Grid.Row="0" Grid.Column="0" Content="{Binding Cards[20]}" ContentTemplateSelector="{StaticResource CardTemplateSelector}"/>
...

<!--right column-->
...

<!--player chips-->
<ContentControl Grid.Row="10" Grid.Column="10" Content="{Binding Players[0]}" ContentTemplate="{StaticResource PlayerTemplate1}"/>
...


What I expect:
1)Model makes a dice roll(actually i have done this)
2)ViewModel gets this result and transform it to position on grid(have some ideas)
3)View must somehow get this position and move my player.







wpf mvvm prism






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 20:23









EugenEugen

12




12













  • You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

    – Wes
    Jan 3 at 21:43











  • My answer to this question should provide you with enough to get started.

    – Mark Feldman
    Jan 3 at 22:41











  • Thank you @MarkFeldman! Can you help another one?

    – Eugen
    Jan 4 at 19:26



















  • You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

    – Wes
    Jan 3 at 21:43











  • My answer to this question should provide you with enough to get started.

    – Mark Feldman
    Jan 3 at 22:41











  • Thank you @MarkFeldman! Can you help another one?

    – Eugen
    Jan 4 at 19:26

















You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

– Wes
Jan 3 at 21:43





You can try placing the player's content controls in each cell then use a visibility converter to only display them at their current position.

– Wes
Jan 3 at 21:43













My answer to this question should provide you with enough to get started.

– Mark Feldman
Jan 3 at 22:41





My answer to this question should provide you with enough to get started.

– Mark Feldman
Jan 3 at 22:41













Thank you @MarkFeldman! Can you help another one?

– Eugen
Jan 4 at 19:26





Thank you @MarkFeldman! Can you help another one?

– Eugen
Jan 4 at 19:26












2 Answers
2






active

oldest

votes


















-1














Thank you MarkFeldman!Your approach helped me. But i have another problem now))



For this moment my players can move all around the game board. It's great! But, I want to simulate the passage of cards one by one, and not immediately to the final card. First I tried to make one step, thread.sleep(100) and then again step until in the right place. But this led to a complete freeze of the program until the chip was in the final card.



I would be grateful for one more hint.






share|improve this answer



















  • 1





    Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

    – Adam Vincent
    Jan 4 at 19:48



















-1














    internal void MakeStep()
{
this.CardIndex++;
}

internal void MakeStep(int count)
{
Task.Factory.StartNew(() => this.StepByStep(count));

}

private void StepByStep(int count)
{
for (int i = count; i > 0; i--)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
this.MakeStep();
Debug.Print(this.CardIndex.ToString());
}), DispatcherPriority.Background);
Thread.Sleep(100);
}
}


Here is my solution for simulating the passage of cards one by one. The problem was in threading!






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029287%2fmove-controls-on-view-from-viewmodel%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    Thank you MarkFeldman!Your approach helped me. But i have another problem now))



    For this moment my players can move all around the game board. It's great! But, I want to simulate the passage of cards one by one, and not immediately to the final card. First I tried to make one step, thread.sleep(100) and then again step until in the right place. But this led to a complete freeze of the program until the chip was in the final card.



    I would be grateful for one more hint.






    share|improve this answer



















    • 1





      Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

      – Adam Vincent
      Jan 4 at 19:48
















    -1














    Thank you MarkFeldman!Your approach helped me. But i have another problem now))



    For this moment my players can move all around the game board. It's great! But, I want to simulate the passage of cards one by one, and not immediately to the final card. First I tried to make one step, thread.sleep(100) and then again step until in the right place. But this led to a complete freeze of the program until the chip was in the final card.



    I would be grateful for one more hint.






    share|improve this answer



















    • 1





      Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

      – Adam Vincent
      Jan 4 at 19:48














    -1












    -1








    -1







    Thank you MarkFeldman!Your approach helped me. But i have another problem now))



    For this moment my players can move all around the game board. It's great! But, I want to simulate the passage of cards one by one, and not immediately to the final card. First I tried to make one step, thread.sleep(100) and then again step until in the right place. But this led to a complete freeze of the program until the chip was in the final card.



    I would be grateful for one more hint.






    share|improve this answer













    Thank you MarkFeldman!Your approach helped me. But i have another problem now))



    For this moment my players can move all around the game board. It's great! But, I want to simulate the passage of cards one by one, and not immediately to the final card. First I tried to make one step, thread.sleep(100) and then again step until in the right place. But this led to a complete freeze of the program until the chip was in the final card.



    I would be grateful for one more hint.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 4 at 19:23









    EugenEugen

    12




    12








    • 1





      Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

      – Adam Vincent
      Jan 4 at 19:48














    • 1





      Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

      – Adam Vincent
      Jan 4 at 19:48








    1




    1





    Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

    – Adam Vincent
    Jan 4 at 19:48





    Consider posting a new question for a new problem, instead of posting it as an answer to your original question.

    – Adam Vincent
    Jan 4 at 19:48













    -1














        internal void MakeStep()
    {
    this.CardIndex++;
    }

    internal void MakeStep(int count)
    {
    Task.Factory.StartNew(() => this.StepByStep(count));

    }

    private void StepByStep(int count)
    {
    for (int i = count; i > 0; i--)
    {
    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
    {
    this.MakeStep();
    Debug.Print(this.CardIndex.ToString());
    }), DispatcherPriority.Background);
    Thread.Sleep(100);
    }
    }


    Here is my solution for simulating the passage of cards one by one. The problem was in threading!






    share|improve this answer




























      -1














          internal void MakeStep()
      {
      this.CardIndex++;
      }

      internal void MakeStep(int count)
      {
      Task.Factory.StartNew(() => this.StepByStep(count));

      }

      private void StepByStep(int count)
      {
      for (int i = count; i > 0; i--)
      {
      System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
      {
      this.MakeStep();
      Debug.Print(this.CardIndex.ToString());
      }), DispatcherPriority.Background);
      Thread.Sleep(100);
      }
      }


      Here is my solution for simulating the passage of cards one by one. The problem was in threading!






      share|improve this answer


























        -1












        -1








        -1







            internal void MakeStep()
        {
        this.CardIndex++;
        }

        internal void MakeStep(int count)
        {
        Task.Factory.StartNew(() => this.StepByStep(count));

        }

        private void StepByStep(int count)
        {
        for (int i = count; i > 0; i--)
        {
        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
        {
        this.MakeStep();
        Debug.Print(this.CardIndex.ToString());
        }), DispatcherPriority.Background);
        Thread.Sleep(100);
        }
        }


        Here is my solution for simulating the passage of cards one by one. The problem was in threading!






        share|improve this answer













            internal void MakeStep()
        {
        this.CardIndex++;
        }

        internal void MakeStep(int count)
        {
        Task.Factory.StartNew(() => this.StepByStep(count));

        }

        private void StepByStep(int count)
        {
        for (int i = count; i > 0; i--)
        {
        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
        {
        this.MakeStep();
        Debug.Print(this.CardIndex.ToString());
        }), DispatcherPriority.Background);
        Thread.Sleep(100);
        }
        }


        Here is my solution for simulating the passage of cards one by one. The problem was in threading!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 20:03









        EugenEugen

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029287%2fmove-controls-on-view-from-viewmodel%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas