Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I would like to enable/disable/hide certain functions based on log/in/out within an application. This is not working as expected. Can someone please direct me as to what I can do to get this to work correctly?
<someControl Text="New Action" Loaded="BtnSomeAction_Loaded" ToolTip="New Action" Visibility="{Binding Converter={StaticResource canDoSomethingBasedOnUserRights}, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"/>

Converter code:
public class CanDoSomethingBasedOnUserRights : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (someValidationConstraint)
            ? Visibility.Visible
            : Visibility.Collapsed;
    }


    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

}

You can switch the converter to enabling the control as well. Can someone please advise as to what I am doing wrong?

Thanks,
Me

What I have tried:

Based on the above, I am not sure what I have missed... :/.. Should I make that particular resource dynamic? (Obviously haven't tried that yet but not sure if that will help)
Posted
Updated 8-Aug-19 11:36am

Your looking in the wrong place; this happens at the user control, Window, data context level.

INotifyPropertyChanged Interface (System.ComponentModel) | Microsoft Docs[^]
 
Share this answer
 
Comments
nortee 8-Aug-19 9:19am    
Hi Gerry,

The object I am binding to does implement the INotifyPropertyChanged interface.
[no name] 8-Aug-19 12:03pm    
Then none of the code you're showing is of use in identifying the problem or what is missing in terms of XAML, binding, public versus private, getter / setters, timing, the callback, ....
nortee 8-Aug-19 17:34pm    
Hi Gerry,

I cannot thank you enough for your responses. I did find the problem and it was a n00b mistake. And it was with regards to my binding portion. I did not apply the binding to the property I was wanting the converter to adjust accordingly. I have tested my update and now it works as expected:

<somecontrol text="New Action" loaded="BtnSomeAction_Loaded" tooltip="New Action" visibility="{Binding SomeControtrollingProperty Converter={StaticResource canDoSomethingBasedOnUserRights}}">
nortee 8-Aug-19 17:42pm    
I do also apologise if the question wasn't as concise as I (or you) would have liked/expected.
As noted, I did resolve the issue. Reason: N00B mistake... :/

Thanks all!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900