|
Gerry Schmitz wrote: Access is at the "transaction level"; not "field".
Not sure what that means. This is why there's an IsEnabled property on the UI elements... to enable or disable them.
Gerry Schmitz wrote: Create specific "functions" (with UI) to accomplish what you want;
That 'function' is a method on the VM.
Gerry Schmitz wrote: even if it means "duplicating" a screen and making some "fields" read-only for that case.
That's rediculous. That would results in THOUSANDS of views to accomadate all possible configurations.
This seems like a solution except in their example they have the method paramaters hard coded. I would need to pass a string along. I could set the Tag on each element and use that.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It's a "pattern"; "Enabling" controls in a ui (for a given transaction) is part of that pattern.
The "function" would correspond to a "menu item"; "step"; etc. Nothing to do with "methods in code" from a "UI POV".
"Change credit limit" is not one of "thousands". It could simply be a tab, group box, etc that is "enabled or disabled". A "transaction code" could be passed to a constructor. Other fields disabled ... if it doesn't confuse. That's what governs a "copy" ... not "thousands".
Use some imagination.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Maybe you're not understanding what I'm trying to accomplish here.
When a user logs in their rights are retrieved and stored on a static class in a Dictionary. See below
public static class AppCore
{
public static Dictionary<string, bool> Rights { get; set; }
public static void Login(string userName, string password)
{
CurrentUser.Rights.ForEach(x => Rights.Add(x));
}
public static bool HasAccess(string itemName)
{
return Rights.Where(x => x.Key == itemName).Select(x => x.Value).FirstOrDefault();
}
}
What I want to do now is call HasAccess from the XAML. All I should have to do is set the key ("CanEditCustomer" or "CustomerCreditLimit"), or maybe the element name, on the UI element.
I have this working already with simply binding to the dictionary and setting the key, as in my original posting... What I'd really like is instead of binding to a property, I want call a method on the VM so I can do advanced logic.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 18-Apr-18 15:01pm.
|
|
|
|
|
Add, change, delete are all "functions".
To say a user "cannot" is redundant; you can simple add a rule to the user that says "can add customer".
At run time, the "ui" can access the "rule" for a given user and transaction, and enabled / disable that "menu item", tab, groupbox etc.
In most cases, the user never gets past the menu based on a rule. And which is friendlier than totally removing a menu item. In your case, if you want to enabled / disable add / edit / replace buttons, you need to establish "intent" first; which transates to less code but a few more menu items (to pass transaction codes).
Your "logging" gets more useable data too.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
We use groups and check on view load but the principle should be the same. We have bool properties for each field that needs controlling - this can be bloody tedious even if you can group fields.
Any event bound to the VM property change can then fire the SetViewState method that checks the state of the bound object and sets the various field bools according to the rules defined.
Caveat this can become a bloody nightmare when you have hundreds of input fields that all need validating based on the user profile and the inputs. Trying to keep it simple can be a nightmare.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Where can I find a C# equivalent (code) for the WPF, Microsoft-hidden Application.Run method?
|
|
|
|
|
|
That web page does not have the C# code equivalent of WPF's Application.Run() method. i.e., with a loop with GetMessage, DispatchMessage, etc.
modified 17-Apr-18 12:33pm.
|
|
|
|
|
As far as I can see it is the same, the difference being that it starts a Windows.Forms application, rather than a WPF one. You need to give more details of your actual problem.
|
|
|
|
|
The present WPF equivalent of what used to be:
BOOL bRet;
while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
{
if (bRet == -1)
{
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
|
|
|
|
|
That is Win32, not .NET, and the .NET equivalent is handled inside the framework.
|
|
|
|
|
That is,
public class Application {
private void Run() {
}
}
|
|
|
|
|
GregJ7 wrote: You would have to ask Microsoft. Or buy an MSDN developer subscription which gives you access to their source code.
|
|
|
|
|
Reference Source[^]
public int Run()
{
EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordGeneral | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WClientAppRun);
return this.Run(null);
}
public int Run(Window window)
{
VerifyAccess();
if (InBrowserHostedApp())
{
throw new InvalidOperationException(SR.Get(SRID.CannotCallRunFromBrowserHostedApp));
}
else
{
return RunInternal(window);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks. I found what I wanted in the Dispatcher class (which class Application uses). I needed to see more than I thought, because there is so much important code, however, what I originally was looking for was basically the following in Dispatcher.PushFrameImpl():
while(frame.Continue)
{
if (!GetMessage(ref msg, IntPtr.Zero, 0, 0))
break;
TranslateAndDispatchMessage(ref msg);
}
From this code I was led to learn about thread Frames and such.
|
|
|
|
|
Has anyone that knows what WPF Application.Run() does written a C# function that duplicates what it does? Can you point me to that code? Thanks.
|
|
|
|
|
I already told you the answer. I also suggested that you explain what problem you are trying to solve.
|
|
|
|
|
Where did you tell me everything what Application.Run() does and how it does it? If you can't understand my question or don't know the answer to my question, then I would like an answer from someone who does.
|
|
|
|
|
I told you where to find the information. Whatever that method does is internal to Microsoft, so they are the people to answer the question. What you have still not done, is to explain exactly what problem (if you actually have one) you are trying to solve.
|
|
|
|
|
You could always take a look at the publicly available[^] reference source code.
This space for rent
|
|
|
|
|
|
I'm old. That took me a minute to translate
You are most welcome.
This space for rent
|
|
|
|
|
I'm trying to drag a user control around a canvas. I want to prevent the user from dragging the control outside the canvas.. See my comment in green.
private void Control_MouseMove(object sender, MouseEventArgs e)
{
var draggableControl = sender as UserControl;
if (isDragging && draggableControl != null)
{
Point currentPosition = e.GetPosition(this.Parent as UIElement);
var transform = draggableControl.RenderTransform as TranslateTransform;
if (transform == null)
{
transform = new TranslateTransform();
draggableControl.RenderTransform = transform;
}
var newX = currentPosition.X - clickPosition.X;
if (newX < 0)
{
newX = 0;
}
if (newX > parent.ActualWidth)
{
newX = parent.Width - this.Width;
}
transform.X = newX;
transform.Y = currentPosition.Y - clickPosition.Y;
}
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Can't you get the position and size of the containing element (canvas) in relation to the window and massage those values into you control position.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I can get a reference to the Canvas, but it doesn't have Left or Top properties.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|