|
You can't template UserControls. You'd need a custom control for that...
See COntrol Authoring Overview[^]
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 14, 2011 7:36 PM
|
|
|
|
|
Thanks for answering an providing a great resource. This will probably explain many issues. Just not at the moment, you know [2:30 AM]. Cheers!
Greetings - Jacek
|
|
|
|
|
Good Day All
I have a strange situation here. When a user logs in i store the username or userid in the Cookie. So i have a generic method that retrieves that value and when i debug this, i can see that the value is retrieved nicely and i assign that value to a property like this
ContactsModel model = new ContactsModel();
model.iUserid = Convert.ToInt32(GenericMethods.GenericMethods.GetCookie("UserID"));
and after that Asynchronously i call the Business Layer WCF Service
like this
business.AddContactNumberAsync(model);
business.AddContactNumberCompleted += new EventHandler<AddContactNumberCompletedEventArgs>(business_AddContactNumberCompleted);
and the Completed Event like this
void business_AddContactNumberCompleted(object sender, AddContactNumberCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result.ToString() == "")
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = "Successfully Added";
lblError.Background = new SolidColorBrush(Colors.Green);
this.DialogResult = true;
}
else
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = e.Result;
lblError.Background = new SolidColorBrush(Colors.Red);
}
}
else
{
lblError.Visibility = System.Windows.Visibility.Visible;
lblError.Content = e.Result;
lblError.Background = new SolidColorBrush(Colors.Red);
}
}
and in my Business Layer Service , i wanted to make if the value is corrupted in the Silverlight side or Business Layer side and i receive a call like this in the Business layere Service
public string AddContactNumber(ContactsModel Model)
{
string Error = string.Empty;
eCashDataLayer.IeCashDatalayerClient Datalayer = new IeCashDatalayerClient();
if (Model.iUserid != 0)
{
Error = Datalayer.AddContactNumber(Model);
}
else
{
Error = "Invalid Userid";
}
return Error;
}
it always return "Invalid Userid" , i am not sure what is the problem because this has been working all along.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I'm not sure what's going on based on your post, but I may have missed something.
But can't you step through in the debugger and see where Model.iUserid becomes 0?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi Mark
I tried , from Silverlight the value is passed to the service , i am just surprised why all of a sudden it does this.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
This[^] is how would be setting a cookie in Silverlight. I did not see any code which did this here.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Good Day Abhinav
this is the exact code i use. The Problem is not in storing and retrieving of the cookie, but it lies in transporting it from the Silverlight to a service.when i pass it to a service method, on the way the value get lost. This code was working for days, after i formated my machine the same thing does not work anymore.
This is my generic functions i use to deal with cookies and when i debug i can see the value be retrieved from a cookie and being passed to a wcf method.
public static void DeleteCookie(string key)
{
DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}
public static void SetCookie(string key, string value)
{
DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}
public static string GetCookie(string key)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
key += '=';
foreach (string cookie in cookies)
{
string cookieStr = cookie.Trim();
if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
{
string[] vals = cookieStr.Split('=');
if (vals.Length >= 2)
{
return vals[1];
}
return string.Empty;
}
}
return null;
}
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
I read about MVVM model. Using MVVM model i can reduce the code behind.
What does it Mean?
As MVVM model is separating the view, Model and ViewModel.
What is the actual use of ViewModel.
can't I bind the data from model itself rather than ViewModel?
Thanks,
Umesh Tayade
|
|
|
|
|
I also just started programming with MVVM pattern and I had a good start looking at Karl Shifflet's MVVM training "In the Box".
Try it out, it should provide you with a brief overview to start with:
In the Box MVVM Training[^]
Kind regards,
Nico
|
|
|
|
|
The two main advantages I see in using the ViewModel is that it allows you to write unit tests and separates the various concerns making for a cleaner implementation.
You can't unit test the code behind your view but you can unit test the ViewModel code. So by seperating your presentation logic from the view itself, you create a more reliable solution. Not sure if you are actually reducing the amount of code. It's just moved to the ViewModel
You can bind directly to the model but writing presentation logic (adding properties, sort routines etc) in the model creates performance issues and confuses other developers about the purpose of the model. So by using the ViewModel class to implement this logic, you can avoid these problems.
The idea behind MVVM is simple, finding good articles which step you through implementing MVVM can be hard to hard to find but MVVM fits nicely with the WPF/Silverlight data binding model.
"You get that on the big jobs."
modified on Saturday, May 14, 2011 7:34 PM
|
|
|
|
|
Member 4550493 wrote: I read about MVVM model. Using MVVM model i can reduce the code behind.
What does it Mean?
You are going to write code for any event (say click) in the view model rather than the code-behind for the view. This completely decouples your UI from the logic inside your event handler.
Member 4550493 wrote: What is the actual use of ViewModel.
The view model is going to act as the intermediary between your UI and the data mmodel.
Member 4550493 wrote: can't I bind the data from model itself rather than ViewModel?
Yes you can. But its cleaner to bind to the view model (though both approaches are equally valid and there are arguments for using each of them).
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Member 4550493 wrote: I read about MVVM model. Using MVVM model i can reduce the code behind.
What does it Mean?
The idea of the code-behind reduction is that you remove any code-behind that is not strictly to do with the presentation of the data - thus you separate the presentation completely, allowing the presentation to be changed independently of the rest of the application.
Member 4550493 wrote: As MVVM model is separating the view, Model and ViewModel.
What is the actual use of ViewModel.
I think of the viewmodel as being what the name suggests - a model of the view. if you're going to have a form that dispays a list, and allows the user to select an item from the list to "do something" with, then the view model will contain a property holding the list's elements, and functionality to "do something" with an element of that list.
You can write tests against the ViewModel without worrying about visual controls, and the ViewModel becomes ,as it were, the specification of the View.
Member 4550493 wrote: can't I bind the data from model itself rather than ViewModel?
Sure you can - but the idea of the viewmodel its to separate your presentation from dependency on your data - and vice versa. In order to present data to the user, you may need to manipulate that data in some way - and if you do this in the model in order to be able to bind to it, then you're tying your Data to the View. Fine in principal, until something changes
As an example. Say you have a Time stored in the DB and you ant to display it - you retrieve it into a model that contains a DateTime value.
You want to display the time as an analogue clock. So you need angles for the hands.
Easy, you say, add properties of HoursAngle, and MinutesAngle to your model and bind to them.
It works - but it's just Not Right, is it? What business has the model got in presenting angles? What if you now decide youwant to display the time as a percentage of the passage of a day? add more properties to the Model?
A better way is for the model to present the time as a datetime, and the ViewModel to provide bindable properties, where necessary, to provide the Gui representations.
(note this isn't necessarily a real world example - there are other ways of presenting an analogue clock than binding to an HoursAngle propery on a Viewmodel or a Model)
I waffled on for four articles about MVVM - which may help, or may not - see my sig for a link
|
|
|
|
|
Hi,
My Project is devoloped with silverlight4.
In my Project i have used some telerik controls with version 3.
But, the problem with my application is it is taking too much memmory.
Actually my Application is showing records for perticular order no,
so, can u help me.
How can i reduce the memory?
Thanks,
Umesh Tayade
|
|
|
|
|
How do you know it's taking too much memory?
If it's your application don't you know how it's using memory?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I had checked it in Task Manager.
Actually i havent devoloped this Application.
I am just going through it and i came to know that it is making full cpu usage.
can suggest me what are the possibilities of it?
How do i overcome it?
Thanks,
Umesh Tayade
|
|
|
|
|
I recently wrote an article about what Telerik did.
They have created something they named "Minifier" it takes your silverlight project and remove unused things and leave you with a optimized project. You should even try their "JustCode" it makes sure you have neat code that has less bugs.
http://www.dotnetfunda.com/articles/article1282-how-to-reduce-the-size-of-your-silverlight-application-with-telerik-minifie-.aspx[^]
Hope it helps
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
hi experts,
I am created a non client area Form and customize the Form's default border style border style, now i am facing a problem is that after i Maximize the window will hide the Window's taskbar
Please Help me
thanks in advanse
|
|
|
|
|
Hi,
another datagrid question :=)
I searched the web for this, but unfortunatelly did not find anything useful.
What I want to achieve is, if the user presses tab on the last visible column of a datagrid, it should automatically create the new line and open the first line for editing data.
So if I'm here:
Screenshot 1
and press tab the datagrid should do this:
Screenshot 2
Any ideas?
Kind regards,
Nico
|
|
|
|
|
Assuming the default TAB behavior (i.e. tabbing out of the final cell moves the focus from the grid to the next control) I would try providing a LostKeyboardFocus that inserts a row, and brings the focus back into the initial cell of that newly inserted row.
P.S. This may or may not work when there are no other controls on the page: I do not know if you get a LostKeyboardFocus+GotKeyboardFocus when the focus circles back to the same control.
|
|
|
|
|
Okay thanks for your answer
But I don't think this is the way I want to go. I thought about something like:
- Event "CurrentCellChanged" or something similar
- If my cursor was in the last visible column and the user pressed "TAB" then do something
But I had no luck putting this correctly together.
I have extreme problems finding out if the Current Cell is in the last visible column...
Kind regards,
nico
|
|
|
|
|
Yeah, that's why I suggested using the lost focus: the event figures out the last visible cell very reliably.
|
|
|
|
|
Ah okay then I didn't understand your first post correctly.
I'll give it a try... 
|
|
|
|
|
In my wpf application, there are several textboxes to show the values of the data in the database.
The storedprocedure used, returns fields such as Notes and EnglishNotes as you see in xaml below.
The problem is that txtNotes always shows the value in txtEnglishNotes
I have checked and the storedprocedure does return the correct value for Notes and EnglishNotes but somehow the two textboxes show the value in txtEnglishNotes always.
Do you see why please?
Thanks
<TextBox Grid.Row="5" Margin="5" Name="txtNotes"
VerticalScrollBarVisibility="Visible" TextWrapping="Wrap"
Grid.ColumnSpan="2"
Text="{Binding Path=Notes}" MaxLength="100" />
<TextBox Grid.Row="12" Margin="5" Name="txtEnglishNotes" Grid.ColumnSpan="2"
VerticalScrollBarVisibility="Visible" TextWrapping="Wrap"
Text="{Binding Path=EnglishNotes}" MaxLength="100" />
|
|
|
|
|
arkiboys wrote: Do you see why please?
Nope, the posted snippet looks fine. Your problem is likely elsewhere.
|
|
|
|
|
Where can the problem be?
I have also checked the SP which returns the correct values for each field.
Thanks
|
|
|
|