AlbertHawking
Topic Author
Posts: 1
Joined: 02 Jun 2022, 14:38

Controlling Visibility of an object

10 Dec 2022, 14:42

Hello Everyone
I stuck in some problem.
I created a project in Noesis that contains set of buttons and set of panels.
I wanted to control the visibility of a panel with buttons changing their parameter visibility from false to true.
This is quite classic approach. I have some experience using Unity and long long time ago Action Script :P (I know I know - i am quite old :P)
I did this construction on the guide: https://github.com/CSharpDesignPro/WPF- ... using-MVVM
in attachments I gave you pictures of current construction:
- button construction in project
- panel construction in project
- logic behind the code of controlling visibility
- additional methods

So in general it should not be rocket science.
I did sone debugging - you can see the message boxes. The variable is changing properly but it not affect the appearance for panel.
No errors while build.
I checked all the NoesisGui samples and I know there are some more complex solutions but I though I do not need them.

Final request - I am aware that probably it is not the best solution but in this particular situation is the simple way to do things I need for demo. So I would be very appreciate if we could focus on this problem. To be honest I am lack of time to implement more complex solution.

So please I need some help

Best Regards
Attachments
Screenshot-2022-12-10-115837.jpg
additional methods
Screenshot-2022-12-10-115824.jpg
code controlling visibility
Screenshot-2022-12-10-115803.jpg
panels
Screenshot-2022-12-10-115727.jpg
buttons
 
User avatar
sfernandez
Site Admin
Posts: 3364
Joined: 22 Dec 2011, 19:20

Re: Controlling Visibility of an object

12 Dec 2022, 19:07

From the xaml you attached I see that you are setting the DataContext locally in the Button:
<Button ...>
  <Button.DataContext>
    <local:ComputerViewModel/>
  </Button.DataContext>
</Button>
This is creating an instance of that ComputerViewModel that is only visible for that button. So it won't be possible for "QuestMapBtn" Grid to listen to the same view model changes.

You probably need a parent viewmodel set in the root of your xaml that exposes the different panel viewmodels, and then bind to the corresponding viewmodel property on each element:
public class MainViewModel
{
  public ComputerViewModel QuestMap { get; }
  ...
}
<Button Command="{Binding QuestMap.ShowPanelCommand}" .../>
...
<Grid x:Name="QuestMapBtn" Visibility="{Binding QuestMap.IsPanelVisible, Converter={StaticResource BooleanToVisibility}}" .../>
Could you try that?

Who is online

Users browsing this forum: No registered users and 4 guests