Create users for a WPF application - wpf

I'm creating an application on which I want different users to use it. I want to insert a variable, only modifiable at development mode. I think maybe there should be a way of using the App.Settings of the WPF Application, but, after one hour googling, I don't have a clear idea yet.
So, I need:
A variable that makes the WPF Application run at administration or client scope
If I have that variable in a specific role, I want to disable some controls
Any idea on where to look for a solution for this?

Well you could add to the base class of your ViewModels a property which contains the value reflecting the mode. As next step you could bind the IsEnabled property of the controls, which shall have this behavior, on this property of their related ViewModel.
Since you don't want to provide different modes with different states a.s.o., this seems to be the best approach.

Related

bind data when user controls can be switched in WP7

I just worked with C# but do not have any idea on Silverlight so I am trying to know if there is a possibility of following.
I have 2 possible layouts for my list box items. so I have created 2 different user controls. Which are completely different that I cannot comprimise and put them in a single control and disable and enable on certain condition. I assumed that this approach will delay the load (correct me if I am wrong). So I am looking for a possibility if I can switch them from xaml. I can switch the control in c# code and even populate them. But data population in c# is a pain when compared to silverlight. I am asking this question only because I want to use data binding.
Is there a way to switch them from xaml. or is there a efficient way of doing this. Even a link of any article that can help is fine.
Thanks in advance.
Maybe DataTemplateSelector will be suitable for you.
I would disagree that data population in Silverlight is a pain.
On the contrary, this is actually one of the strongest benefits with Silverlight and Xaml, because of the excellent data binding capabilities you have access to.
So if you don't already, make sure you actually are utilizing this properly.
I don't know exactly how you would like to switch between these different views, but one way would certainly to bind the visibility of your views to another element on the page that determines which of them should be visible.
That way you can do it within Xaml.

Design Time Extension Properties In Winforms

I have built out a couple of keyboards for a touch aware app we are building in work. Since we use a controller that is aware of when the app is in touch screen mode I thought it would be nice if, in design mode, we could associate a control with a keyboard type and have the controller look after the calling of the keyboard.
One of the things I do not want to do is to sub class each type of control just to add this property as I feel it is a very heavy for small gain. I had thought of using the tag property but it is not available in all controls due to use.
I was wondering if there is a way of attaching a property to a control on design time for the purpose of adding this meta data. So to recap I would like to be able to give each control a value that would be read by the controller to decide what keyboard to show.
Yes, the designer supports this. Good examples of existing components that do this are ErrorProvider and HelpProvider. Note how they add properties to existing control types.
You'll want to implement your own component, it needs to implement the IExtenderProvider interface. The MSDN Library article for it has a good example that should help you getting it right.

Central datacontext on WP7 Mango or not?

I'm starting to migrate one app to WP7 Mango now. One of the reasons is the database support :-)
Technically the database thing is really clear. But I'm a bit unsure where should I put my datacontext. I see primary two options:
global datacontext for everything
a separate datacontext instance per app feature
I would like to have some thoughts on that.
Thanks!
The demo included with the SQLite2CE tool might help you in that it gives an example of how to use datacontext and ViewModels. Visit http://sqlite2ce.codeplex.com/ and download the package, the linked articles on this page will also be a help. As a bonus, if you haven't yet converted your database from SQLite then the tool will help you with that as well.
If you take a look at the demo there's a MainViewModel (set as the datacontext of the application's MainPage.xaml) which contains an ObservableCollection for each referenced class of data. A second ViewModel is used to compile a custom set of data from the database but is still referenced though an ObservableCollection in MainViewModel. This way each control you wish to bind in XAML only needs to reference a column within the appropriate ObservableCollection object.
At the moment I'm would use multiple datacontext for the different features. I'll tried to use a single one through the singleton pattern. This caused some exceptions because you'll need to syncronize the SubmitChanges() calls - especially if different threads are used.

Silverlight 4 + Prism create controls at runtime

I'm creating a Silverlight 4 application to manage active directory objects (CRUD Users, groups etc). Now we all know that active directory objects have lots of properties.
I want to save some groups of property names in an SQL DB (ie, samaccountname, mail, etc.) for certain AD object types (users, groups, etc).
When a user in the silverlight app clicks on "create user" I want to
get all the property names I defined in the sql db for the user
create a pre defined silverlight control for each property and add it to the current "create view"
be able to read all the values the user enters in the controls and pass them on
The user controls differ depending on the type of the Active Directory property, i.e. for a property with a datetime value, we will create a user control with a calendar. This way we can keep the "Create" Views dynamic.
The Silverlight / Prism foundation is already there and I'm adding my Views via the RegionManager. It all works just fine but I'm not sure how to add controls in such a dynamic way that it still works with PRISM and the MVVM pattern. Thank you for any input.
I'm going to assume that your comfortable with the getting the properties from the db and saving the values back and focus on the middle area of creating the view with MVVM in mind.
The PRISM part I wouldn't worry about. You say you've got the views registered with the region manager and that's about all you need to do.
My initial thought was how would you "create" controls at runtime with MVVM considered. Creating controls is not the hard part but would require a handle on the element you will be injecting these into, a root grid for example. This would on the surface feel very un-MVVM. Personally I think it's valid to have "view" code done the old fashion way, it's the "data" code used in binding that should be MVVM'd. The issue is telling the code that will inject the controls on to the view what to actually inject. I can't think of a neat way to do this.
As a solution could you not create a view containing all the controls that apply to each of the properties and rather than "create" them when needed "hide" them when not needed? You could bind the "Visibility" property (probably through a value converter) to a property in the ViewModel that can be used to determine if that particular control should be shown or not. If these where placed in a stack panel then the view would dynamically shrink.
If you think a code example would help let me know.

Authentication and Roles in WPF

I am doing a project in WPF. I got a requirement to authenticate a user and providing accessibilty for the modules based on the role. Do i have a better way to achieve this in WPF.
It will depend in part on how secure you need the code to be.
For all your use cases, though, use a Model-View-ViewModel pattern. In each ViewModel, perhaps best placed in a base class for all your ViewModel classes, include a state variable which returns a string and raises the PropertyChanged event whenever the security state changes.
Base your presentation for each View class on the value of that string, following a pattern similar to the accepted answer to this SO question:
https://stackoverflow.com/questions/3868164/
The answer describes how to do this with boolean values, but you can use any string value other than "True" or "False" if your ViewModel state variable needs more than two states.
All .NET code, including WPF, can be easily reverse-engineered. If your code needs to be more secure than that, that is, if your use case assumes that your users will hack your WPF program, then you will want to obfuscate and/or encrypt much of the ViewModel code, using commercially available products like InishTech's SLPS or Dotfuscator or whatever.
Alternatively, you could use the same MVVM pattern and write a Silverlight application, but I'm not sure if a Silverlight user has access to the binary files the way a desktop WPF user would.

Resources