Click here to Skip to main content
14,303,133 members

Silverlight / WPF

 
GeneralRe: WPF Toolkit PropertyGrid Pin
Kevin Marois5-Jun-18 10:24
professionalKevin Marois5-Jun-18 10:24 
GeneralRe: WPF Toolkit PropertyGrid Pin
Richard Deeming6-Jun-18 1:21
mveRichard Deeming6-Jun-18 1:21 
QuestionStyle Problem Pin
Kevin Marois9-May-18 12:03
professionalKevin Marois9-May-18 12:03 
AnswerRe: Style Problem Pin
Mycroft Holmes9-May-18 14:25
memberMycroft Holmes9-May-18 14:25 
QuestionDataGrid Template Column Binding Pin
Kevin Marois9-May-18 5:05
professionalKevin Marois9-May-18 5:05 
AnswerRe: DataGrid Template Column Binding Pin
Nathan Minier9-May-18 7:15
professionalNathan Minier9-May-18 7:15 
GeneralRe: DataGrid Template Column Binding Pin
Kevin Marois9-May-18 9:48
professionalKevin Marois9-May-18 9:48 
GeneralRe: DataGrid Template Column Binding Pin
Nathan Minier10-May-18 1:04
professionalNathan Minier10-May-18 1:04 
QuestionDataGrid DataGridCheckBoxColumn Property Change Not Firing Pin
Kevin Marois2-May-18 6:52
professionalKevin Marois2-May-18 6:52 
AnswerRe: DataGrid DataGridCheckBoxColumn Property Change Not Firing Pin
Richard Deeming2-May-18 8:40
mveRichard Deeming2-May-18 8:40 
GeneralRe: DataGrid DataGridCheckBoxColumn Property Change Not Firing Pin
Kevin Marois2-May-18 9:46
professionalKevin Marois2-May-18 9:46 
QuestionWPF NIC counters Pin
Member 138058691-May-18 13:33
memberMember 138058691-May-18 13:33 
AnswerRe: WPF NIC counters Pin
Gerry Schmitz2-May-18 11:27
mveGerry Schmitz2-May-18 11:27 
QuestionMagnify shader effect Pin
Nick Hallas1-May-18 10:33
memberNick Hallas1-May-18 10:33 
AnswerRe: Magnify shader effect Pin
Gerry Schmitz2-May-18 11:39
mveGerry Schmitz2-May-18 11:39 
QuestionAssign Collection Items In XAML Pin
Kevin Marois23-Apr-18 8:40
professionalKevin Marois23-Apr-18 8:40 
AnswerRe: Assign Collection Items In XAML Pin
Richard Deeming23-Apr-18 8:58
mveRichard Deeming23-Apr-18 8:58 
GeneralRe: Assign Collection Items In XAML Pin
Kevin Marois23-Apr-18 9:25
professionalKevin Marois23-Apr-18 9:25 
AnswerRe: Assign Collection Items In XAML Pin
Maciej Los23-Apr-18 9:56
protectorMaciej Los23-Apr-18 9:56 
GeneralRe: Assign Collection Items In XAML Pin
Kevin Marois23-Apr-18 10:00
professionalKevin Marois23-Apr-18 10:00 
GeneralRe: Assign Collection Items In XAML Pin
Richard Deeming24-Apr-18 1:14
mveRichard Deeming24-Apr-18 1:14 
QuestionMouseEventArgs.CLicks in WPF Pin
Enobong Adahada20-Apr-18 6:33
memberEnobong Adahada20-Apr-18 6:33 
AnswerRe: MouseEventArgs.CLicks in WPF Pin
Gerry Schmitz20-Apr-18 13:18
mveGerry Schmitz20-Apr-18 13:18 
GeneralRe: MouseEventArgs.CLicks in WPF Pin
Enobong Adahada21-Apr-18 13:08
memberEnobong Adahada21-Apr-18 13:08 
QuestionField Level Rights Pin
Kevin Marois18-Apr-18 7:38
professionalKevin Marois18-Apr-18 7:38 
I want to implement user access rights at the field level. This is what I've come up with so far. It works well but I have one drawback:

Code Behind
public partial class MainWindow : Window, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    // Dictionary of rights
    private Dictionary<string, bool> _Rights;
    public Dictionary<string, bool> Rights
    {
        get { return _Rights; }
        set
        {
            if (_Rights != value)
            {
                _Rights = value;
                RaisePropertyChanged("Rights");
            }
        }
    }

    // Bound data. Could be defined here or on a model
    private double _CreditLimit;
    public double CreditLimit
    {
        get { return _CreditLimit; }
        set
        {
            if (_CreditLimit != value)
            {
                _CreditLimit = value;
                RaisePropertyChanged("CreditLimit");
            }
        }
    }

    public MainWindow()
    {
        InitializeComponent();

        this.DataContext = this;

        // The property bound to the textbox's Test property
        CreditLimit = 125000;

        // Dictionary of rights
        Rights = new Dictionary<string, bool>();
        Rights.Add("creditLimit", false); // The user cannot access the Credit Limit textbox
    }

    private void RaisePropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

XAML
<TextBox Text="{Binding CreditLimit, Mode=TwoWay}"
            IsEnabled="{Binding Rights[creditLimit]}"
            Width="100"
            HorizontalAlignment="Left"
            Margin="10"/>

The rights, and therefore access to the field, could be changed at runtime by simply doing
Rights["creditLimit"] = true;
RaisePropertyChanged("Rights");

The only drawback is that you really can't run any logic, meaning run specific code to determine if a textbox can be enabled. For example, the requirements for enabling the Credit Limit field might be
  1. The user has rights to modify the credit limit
  2. The customer is in good standing (their credit is still good)
  3. The customer does not have a balance
In this case I would not only want to check the rights list, but also some conditions on the Customer model. Where would this code go?

It is possible to somehow run a method on the VM from the IsEnabled property in the XAML?

I could try to use a multiinding but this puts the business logic in the XAML and would be messy and hard to maintain.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.