-
- AlbertHawking
- Posts: 1
- Joined:
Controlling Visibility of an object
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
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
-
-
sfernandez
Site Admin
- Posts: 3364
- Joined:
Re: Controlling Visibility of an object
From the xaml you attached I see that you are setting the DataContext locally in the 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:
Could you try that?
Code: Select all
<Button ...>
<Button.DataContext>
<local:ComputerViewModel/>
</Button.DataContext>
</Button>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:
Code: Select all
public class MainViewModel
{
public ComputerViewModel QuestMap { get; }
...
}Code: Select all
<Button Command="{Binding QuestMap.ShowPanelCommand}" .../>
...
<Grid x:Name="QuestMapBtn" Visibility="{Binding QuestMap.IsPanelVisible, Converter={StaticResource BooleanToVisibility}}" .../>Who is online
Users browsing this forum: No registered users and 4 guests