CustomValidation Annotation Event Raise Issue MVVM Silverlight 5 - silverlight

I've Created a Model which have few custom validation. These custom validation I've annotated at property by below code
[CustomValidation(typeof(ItemmasterModel), "ValueTextMaxLenghtValidate")]
public decimal Valuetextmaxlength
{
get
{
return _Valuetextmaxlength;
}
set
{
ValidateProperty("Valuetextmaxlength",value);
_Valuetextmaxlength = value;
RaisePropertyChanged(() => Valuetextmaxlength);
}
}
public static ValidationResult ValueTextMaxLenghtValidate(object obj, ValidationContext context)
{
var itmmstr = (ItemmasterModel)context.ObjectInstance;
if (itmmstr.SelectedValuetypeDd != null)
{
string vtype = itmmstr.SelectedValuetypeDd.Key.ToString();
if (vtype.Equals("C"))
{
if (itmmstr.SelectedItemValueCodeTypesDd != null)
{
string vcode = itmmstr.SelectedItemValueCodeTypesDd.Key.ToString();
if (vcode.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
}
else if (vtype.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
return ValidationResult.Success;
}
Now this validation code depend on other property. scenerio When User select a value from dropdown it makes 1 checkbox selected automatically and User should enter the value in texbox also.
Issue:
Validation is working. checkbox is selected at first time then also it comes with error popup.
untill user doesn't make changes into this checkbox or texbox it is with error only. 1 time it says error even value has been entered .Next time it goes even user have not entered anything but during final full object validation is again comes with error.
Why this even ambiguity is happening. How to solve this.
Need more code let me know. I'll Post. Code is in Silverlight 5, MVVM Light

During my Custom validation I was using ValidateProperty("Valuetextmaxlength",value); before setting the value of property so It was giving me issue but the moment I set the value first and then Use my ValidateProperty("Valuetextmaxlength",value); everything worked smooth. Still I don't know the reason why but It worked for me.

Related

Excel-like behaviour of Grids in Ext JS

I'm trying to figure out a way to have an Excel-like behavior with the Grids on Ext JS.
Here is the sample grid I am working with. So far we can already naviguate through the cells with the arrows but only in edit mode.
However what I am trying to reach is the naviguation with the arrows, TAB and Enter keys outside of the edit mode, just like excel.
I tried to integrate this piece of code which overrides the Editor class, hoping that it would change the behavior of the cells but it doesn't change a thing.
I believe this is the most important part that overrides the Editor class and tries to include the keys input :
Ext.override(Ext.Editor, {
startEdit: function (el, value) {
var me = this,
field = me.field;
me.completeEdit();
me.boundEl = Ext.get(el);
value = Ext.isDefined(value) ? value : me.boundEl.dom.innerHTML;
if (!me.rendered) {
me.render(me.parentEl || document.body);
}
if (me.fireEvent('beforestartedit', me, me.boundEl, value) !== false) {
me.startValue = value;
me.show();
field.reset();
if (deleteGridCellValue) {
field.setValue('');
me.editing = true;
me.completeEdit();
deleteGridCellValue = false; // reset global variable
}
else {
if (newGridCellValue == '') {
// default behaviour of Ext.Editor (see source if needed)
field.setValue(value);
}
else {
// custom behaviour to handle an alphanumeric key press from non-edit mode
field.setRawValue(newGridCellValue);
newGridCellValue = ''; // reset global variable
if (field instanceof Ext.form.field.ComboBox) {
// force the combo box's filtered dropdown list to be displayed (some browsers need this)
field.doQueryTask.delay(field.queryDelay);
}
}
me.realign(true);
field.focus(false, 10);
if (field.autoSize) {
field.autoSize();
}
me.editing = true;
}
}
}
});
This is the first time that I am working on a project that is outside of Comp-Sci classes so any help would be very much appreciated. Thanks !

How do you properly set a custom profile property in DNN?

I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.
So, how do you properly set a custom profile property in DNN?
UserInfo.Profile.SetProfileProperty("key","value")
// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");
// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);
// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");
Note: I also tried InitialiseProfile but that didn't change the behavior.
Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.
public string SomeKey
{
get
{
var ppd = UserInfo.Profile.GetProperty("SomeKey");
if (ppd.PropertyValue == string.Empty)
{
var SomeKeyValue = "blah"
//update the user's profile property
UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
//save the user
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
//retrieve again
return SomeKey;
}
string returnValue = ppd.PropertyValue ??
(String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
return returnValue;
}
}

Smartgwt: How to get checkbox value on a listgrid?

I've a listener on cellClick, I get the selected Record but I can't find a way to understand if this record is checked
Method ListGrid.isSelected(ListGridRecord) returns true if row is selected, not if is checked
My Code:
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
listGrid.addCellClickHandler(new CellClickHandler() {
#Override
public void onCellClick(CellClickEvent event) {
if(event.getColNum() == 0 && idMenu != null){
boolean isChecked = event.getRecord().???;
if(isChecked)
....
else
....
}
I've tried also with event.getRecord().getAttributeAsBoolean("_checkField") with no success...
I found a simply solution...
My task is solved using a special boolean field in the DataSource named, for example, "checked"
In ListGrid I've a field "checked", and with a RecordClickHandler I can manage check or uncheck event.
DataSource code:
DataSourceBooleanField checkField = new DataSourceBooleanField("checked");
ListGrid code:
listGrid.addRecordClickHandler(new RecordClickHandler() {
#Override
public void onRecordClick(RecordClickEvent event) {
Record rec = event.getRecord();
boolean checked = rec.getAttributeAsBoolean("checked");
if(checked){
...
}else{
...
}
rec.setAttribute("checked", !checked);
catPgrid.saveAllEdits();
catPgrid.refreshFields();
}
});
ListGridField checkField = new ListGridField("checked", "Sel");
Maybe getSelectedRecords() method would help you!
Here is an API reference: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/grid/ListGrid.html#getSelectedRecords()
Definitely this will provide all records which are selected (using checkbox) but there should be some values which you could use for identifying each record uniquely!

Issue with focus element in GotFocus/Activated event

There is form with text element that should receive focus every time form shown.
In .NET CF Form has no OnShow(n) event
I try to use workaround:
MyForm_GotFocus() // or MyForm_Activated
{
txtTextControl.Text = string.Empty;
txtTextControl.Focus()
}
txtTextControl_GotFocus()
{
txtTextControl.SelectAll()
}
Code for getting form instance:
public static MyForm GetForm
{
get
{
if (s_inst == null || s_inst.IsDisposed)
{
s_inst = new MyForm();
}
return s_inst;
}
}
public static void ShowForm()
{
var frm = GetForm;
frm.Show();
}
1) First time ShowForm (Form instance has been created): txtTextControl emptied and got focus, txtTextControl_GotFocus event raised
2) Second time ShowForm : OK too
3) Third time ShowForm : txtTextControl emptied, but does not get focus
Is there bug or feature? Is there workaround? Show I rewrite ShowForm? Is OpenNETCF.IOC.UI is better solution (50 forms in project)?
I had that same question once.
Set the TabIndex for the control to 0.

WPF CheckBox Binding - Altering value in Property Set does not affect UI

i have a simple checkbox
<CheckBox IsChecked="{Binding ForceInheritance}"/>
In Code i have a class with "INotifyPropertyChanged" and the Property
public bool ForceInheritance
{
get { return forceInheritance; }
set
{
if (forceInheritance != value)
{
value = SomeTest();
if (forceInheritance != value)
{
//something is done here.
}
OnPropertyChanged("ForceInheritance");
}
}
}
If SomeTest() returns !value so the underlying data does not have to change the CheckBox still changes its IsChecked state.
For example:
ForceInheritance is false.
CheckBox is clicked.
SomeTest() returns false.
--> The underlying data is not changed
--> I would expect the CheckBox to stay unchecked
The CheckBox gets checked.
What can i do to not change the IsChecked state of the CheckBox when the setter does not actually change the value?
I thought the "OnPropertyChanged("ForceInheritance");" would do the trick but it didn't.
Thank you for your time.
This problems occurs because when you click checkbox it s value is changed. Then binding causes property set. There you manipulate with its value and hope that calling OnPropertyChanged will cause back binding action updating checkbox value. But doesn't work because updating control after updating property may produce infinite updating loop. To prevent this PropertyChanged is ignored.
What can you do is to move some logic of your property setter to binding validation rule. You can read here about validation rules or leave a comment if you need more information or examples.
Hope it helps.
I would expect the CheckBox to stay unchecked
Now, it seems that CheckBox working as you expect. Something must have changed recently because it works differently now.
Previously
When I needed to correct a value in the setter I use Dispatcher.
public bool IsActive
{
get => _isActive;
set
{
if (_isActive != value)
{
if (value)
{
if (!CanActive())
{
Application.Current.Dispatcher.BeginInvoke((Action)(() => IsActive = false));
return;
}
}
_isActive = value;
OnPropertyChanged(nameof(IsActive));
}
}
}
Now
Now, I don't have to change a value back to false. This works even if I remove OnPropertyChanged call, because after the setter is called, the getter is also called. It looks like the CheckBox is now correcting its state.
public bool IsActive
{
get => _isActive;
set
{
if (_isActive != value)
{
if (value)
{
if (!CanActive())
{
return;
}
}
_isActive = value;
OnPropertyChanged(nameof(IsActive));
}
}
}

Resources