Ok lets see if I'm doing this right, or am I doing it the hard way.
First. I have a account level that's a integer (0-255) each Byte is set to enable given functions. I'm working on setting up the Visibility to a Given Byte Psudo XML Code
<Button Grid.Column="0" Grid.Row="0" Name="Function" Content="Function 1" Visibility="{Binding UserLevel.Allow1 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="1" Name="Function" Content="Function 2" Visibility="{Binding UserLevel.Allow2 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="2" Name="Function" Content="Function 3" Visibility="{Binding UserLevel.Allow3 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="3" Name="Function" Content="Function 4" Visibility="{Binding UserLevel.Allow4 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="4" Name="Function" Content="Function 5" Visibility="{Binding UserLevel.Allow5 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="5" Name="Function" Content="Function 6" Visibility="{Binding UserLevel.Allow6 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="6" Name="Function" Content="Function 7" Visibility="{Binding UserLevel.Allow7 , UpdateSourceTrigger=PropertyChanged}"/>
<Button Grid.Column="0" Grid.Row="7" Name="Function" Content="Function 8" Visibility="{Binding UserLevel.Allow8 , UpdateSourceTrigger=PropertyChanged}"/>
When a User signs in , the class ProgramVar.ActiveUser gets pulled and set to the current signed in User from a PHP Soap Interface (working)
class ProgramVar : INotifyPropertyChanged
{
private User _ActiveUser;
private Level _UserLevel;
public User ActiveUser { get { return this._ActiveUser; } set { _ActiveUser= value; UpdateLevel(); NotifyPropertyChanged("ActiveUser "); } }
public Level UserLevel { get { return this._UserLevel; } set { _UserLevel= value; NotifyPropertyChanged("UserLevel"); } }
private void UpdateLevel()
{
UserLevel.Allow1 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 1) UserLevel.Allow1 = Visibility.Visible;
UserLevel.Allow2 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 2) UserLevel.Allow2 = Visibility.Visible;
UserLevel.Allow3 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 4) UserLevel.Allow3 = Visibility.Visible;
UserLevel.Allow4 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 8) UserLevel.Allow4 = Visibility.Visible;
UserLevel.Allow5 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 16) UserLevel.Allow5 = Visibility.Visible;
UserLevel.Allow6 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 32) UserLevel.Allow6 = Visibility.Visible;
UserLevel.Allow7 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 64) UserLevel.Allow7 = Visibility.Visible;
UserLevel.Allow8 = Visibility.Collapsed; if(ActiveUser.AccountLevel & 128) UserLevel.Allow8 = Visibility.Visible;
NotifyPropertyChanged("UserLevel");
}
}
class User
{
string UserName;
string FirstName;
int AccountLevel;
}
class Level
{
Visibility Allow1 = Visibility.Visible;
Visibility Allow2 = Visibility.Visible;
Visibility Allow3 = Visibility.Visible;
Visibility Allow4 = Visibility.Visible;
Visibility Allow5 = Visibility.Visible;
Visibility Allow6 = Visibility.Visible;
Visibility Allow7 = Visibility.Visible;
Visibility Allow8 = Visibility.Visible;
}
Now I'm also reading about IValueConverters, would using the current method be the proper method, or should I be using IValueConverts in the XAML & the CS Files?
The Current method I'm using is working, as when I tried to use the IValueConvertes, I didn't see how to get a object to return multiple Visibilities (or other varables if needed)