C
C#•11mo ago
mauriziopatino

WPF Visibility binding seems that is not setting style

Hi, i have a vertical navigation bar which my <Border> tag is binded to "IsNavBarVisible": Inside of the Border i have a Grid with the width, background color defined and all the definitions of buttons, icons and their references to static resource design
<Border Grid.Column="0"
Background="{StaticResource BackgroundColor}" Visibility="{Binding IsNavBarVisible}">
<Border Grid.Column="0"
Background="{StaticResource BackgroundColor}" Visibility="{Binding IsNavBarVisible}">
When my MainViewModel loads I set the property to false because the LoginViewModel appears:
public MainViewModel(...parms)
{
...parms
_isNavBarVisible = "Hidden";

}
public MainViewModel(...parms)
{
...parms
_isNavBarVisible = "Hidden";

}
Then, when I run the LoginCommand in my LoginViewModel i set the property to "Visible":
_mainViewModel.IsNavBarVisible = "Visible";
_mainViewModel.IsNavBarVisible = "Visible";
But the problems it's that i just only get a white bar with width property but not the styles applied in my resource dictionary, any help?
No description
8 Replies
mauriziopatino
mauriziopatinoOP•11mo ago
This is how it's supposed to be, i get this by changing the property of IsNavBarVisible to "Visible" in MainViewModel constructor
public MainViewModel(...parms)
{
...parms
_isNavBarVisible = "Visible";

}
public MainViewModel(...parms)
{
...parms
_isNavBarVisible = "Visible";

}
No description
nohopestage
nohopestage•11mo ago
You do call OnPropertyChanged in the property setter, right?
mauriziopatino
mauriziopatinoOP•11mo ago
Yes
No description
nohopestage
nohopestage•11mo ago
I'm not sure why it behaves like that, but you could remove the navbar from the main view and create a separate view that would include the navbar. In that second view host you could host the views that are visible when the user is logged in. That way, when the user is on the login view, they don't see the navbar. When they log in, it shows up and stays there, so you don't have to show/hide it manually
mauriziopatino
mauriziopatinoOP•11mo ago
Yeah it's weird, i don't get it after hours trying to fix it
Honza K.
Honza K.•11mo ago
I dont think the property can be of type string, it should be of a correct type, which is Visibility in this case or you can use binding converter
mauriziopatino
mauriziopatinoOP•11mo ago
string property is working, when i hardcode "Visible" in my MainViewModel conustructor the navbar appears Here is the snippet and also the resulkt
Honza K.
Honza K.•11mo ago
oh, my bad for not reading your question/problem properly 😄 sry
Want results from more Discord servers?
Add your server