|
_Maxxx_ wrote: I don't understand why you say this? Lets say I will have a page
showing a list of customers, and also the individual fields from the currently
selected customer. In MVVM I would create a VM for the page, and
also (because the functionality is self-contained) a VM for the list of
customers and a VM for the individual Customer fields (that is, ONE VM with
properties for each Customer field) Now, my Page VM is nonsense
without having a CustomerListVM and a CustomerEditVM somehow contained within
it. It certainly doesn't know about the VIEWs but it MUST know
about the ViewModels Similarly neither the customerListVM nor the
CustomerEditVM can know about the PageVM - they need to exist
independently. so surely my PageVM legitimately can say "I want to
display this list of customers" - and give the list to the CustomerListVM?
If you check out the problem that the user describes, it's not the same issue that you are describing here. What you describe is a perfectly acceptable solution where you have one view containing data derived from several VMs, where the containing VM is still being displayed.
What the OP described however was a different scenario. He has moved the implementation out of a single view into multiple views, and there is no real physical interaction between these views other than the fact that they were all originally part of one larger VM. The key point here is that the view/viewmodel interaction here is no longer with the "parent" VM, it's with the child VM. This means that, conceptually, the new VM can exist without knowledge of the old VM. The Model part, which has been entirely forgotten about in this situation, can be the same model (and is the one I would choose). So, rather than having to contort the code to worry about maintaining this disconnected list of VMs, it makes more sense to just have the child VM use the same model. Remember that a lot of people mistake the model for always being the data layer; it doesn't have to be, so a simple containing model makes this scenario a whole lot easier.
|
|
|
|
|
Thanks Pete - I was interpreting the OP differently - on re-reading after your post, I follow your logic.
cheers
|
|
|
|
|
No problems mate. It took me two readings to get what he wanted right in my head.
|
|
|
|
|
At this point I introduce my bastardisation and have 1 CustomerVM that would service all 3 of your views.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: 1 CustomerVM that would service all 3 of your views.
that's fine - but what if you want to use the customer lookup view elsewhere - not for editing a customer but for selecting a customer for some other function (say during order entry) You don't want to use that VM with all its overhead do you? soyou would end up with aniother ViewModel supporting the Customer lookup View...
I appreciate you call it a bastardisation - but what you're really doing is treating the containing user control as a View, with a ViewModel, and the other two as user Controls (not views) so they don't have a view model any more than a text box or combo box would. And that's fine - I just find it very confusing if you call something a View that is really just a control - and if it's not just a control, i.e. if it is a View, then it should be modelled by a ViewModel -and a ViewModel's job is to model a view (otherwise they'd be called ViewsModels)
|
|
|
|
|
Oh I'm flexible, for simple list/add dialog/detail I often have 2 views and a dialog using the same VM. If a view is particularly complex then it gets it's own VM even if that is duplicating info already in an existing VM. And no I have no intention of renaming them VsM
_Maxxx_ wrote: I just find it very confusing if you call something a View that is really just a control
The list view is the entry point into the structure, the detail view is distinct, navigated to via a double click from the datagrid on the list view, the add dialog is obviously a childwindow from the list view. All 3 use the same VM, calling the detail view a control is not correct, the dialog maybe.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: All 3 use the same VM, calling the detail view a control is not correct, the dialog maybe.
I see exactly what you're talking about - and it's really down to terminology - but in my view (pub intended) the VM models a V, and if there isn't a specific Vm then it's not a V, it's just a control - as it cannot be used (or tested) stand-alone.
It was partly because of this that I introduced the concept of ViewData separate from (but used by) the ViewModel
|
|
|
|
|
Good Day All
I have a Generic function that in my Static Class. i have this Class in Silverlight
public static BitmapSource LoadImage(Byte[] imageBytes)
{
BitmapImage bmpImage = new BitmapImage();
MemoryStream mystream = new MemoryStream(imageBytes);
bmpImage.SetSource(mystream);
return bmpImage;
}
Now this looked fine for me until i had to bind an Image in Silverlight like this
PhotoHolder.Source =GenericMethods.LoadImage(model.imbPhoto);
The Images i have in the Database are Supported by silverlight they are jpg type.
and the Elelment that i am binding to look like this in Silverlight
<Image x:Name="PhotoHolder" Height="98" Width="102" OpacityMask="Black" Canvas.Left="141" Canvas.Top="30">
<Image.Effect>
<DropShadowEffect/>
</Image.Effect>
</Image>
so if i bind i get this Error
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
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/
|
|
|
|
|
Where does the exception occur??
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi
it happen on this line
bmpImage.SetSource(mystream);
i have used the Correct Image Format that are supported in Silverlight.
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/
|
|
|
|
|
It should work with valid JPEG bytes...
I tested your LoadImage() method but with JPEG bytes loaded from disk and it works fine:
private void loadButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofdlg = new OpenFileDialog();
ofdlg.Filter = "Image Files (*.jpg, *.jpeg, *.png)|*.jpg;*.jpeg;*.png";
if (true == ofdlg.ShowDialog())
{
long filelength = ofdlg.File.Length;
Byte[] imageBytes = new byte[filelength];
using (FileStream fs = ofdlg.File.OpenRead())
{
fs.Read(imageBytes, 0, (int)filelength);
}
PhotoHolder.Source = GenericMethods.LoadImage(imageBytes);
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Now i have a Different Error in the same place
Error HRESULT E_FAIL has been returned from a call to a COM component.
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/
|
|
|
|
|
Silverlight COM component? hmm I have no idea. It works fine for me with valid JPEG files (and PNG files).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
trying to copy and paste text containing hyperlink from one richtextbox to another with TextPointer position as parameter.
tried using the following code but couldn't figure out what the problem is. it did not work.
private Hyperlink GetHyperlinkAncestor(TextPointer position)
{
Inline parent = position.Parent as Inline;
while (parent != null && !(parent is Hyperlink))
{
parent = parent.Parent as Inline;
}
return parent as Hyperlink;
}
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
I have created a WPF control, which I want to deploy to the user.
I need to create an installer for this control. Installer should create a custom tab in VS toolbox and place the control inside that tab, the way it is done by other WPF control installers (e.g., Telerik).
Any help/idea?
|
|
|
|
|
|
Many thanks for your reply. I tried google before asking question here, but none of them (including this one) could fulfill my requirement.
When I install Telerik with the help of their EXE, it just installs everything without being specific to any application. It puts that control into a specific tab in VS toolbox and also places it into 'Assets' tab of 'Expression Blend' without asking any question.
This .vsi file, including dialog box and messages, seems to be specific to Visual Studio and asks questions before installing.
|
|
|
|
|
This [^]could help you as well.
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 All
I have another question. I have a Silverlight application and in one of the Silverlight pages i am hosting an Asp.net Page using a RadhtmlContainer(Telerik). I created a Cookie in Silverlight like this
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);
}
and i have the same generic function to access it like this
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;
}
so i am trying to access this cookie in an asp.net page that is hosted on the the html Container , but i dont find the cookie.
Basically what i want to Achieve is
i want to access a value that is being created in Silverlight e.g "userid" "Username" normally i store it in the Cookie , so now i want to do a database insert , i need to do that insert from that asp.net page, but i cant get hold of that cookie value.
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/
|
|
|
|
|
What do you see in HtmlPage.Document.Cookies when you enter the GetCookies method? It would really help if you set a breakpoint there and told us what was in that part? Plus, and I know this seems obvious, but make sure that the SetCookie method is called before you call GetCookies.
|
|
|
|
|
Good Evening Pete
Thank you for your kind response.
The First thing i do is to set the Cookie when the User has Just Logged in and after that that the User will be redirect to a Welcome page. There are Menu's that are visible for the User to select , and one of them will lead to a Silverlight page that will require the Cookie value that has been set at Login.
So the above explanation your last point that i should first set the Cookie and Access it later
To answer the first question about the htmlpage.Document.Cookies , it has an empty string i am not sure why.
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/
|
|
|
|
|
From your description, the cookies are added by the website and not by Silverlight. It looks like you are trying to read the cookies created in the ASP.NET side, in your Silverlight code. According to MSDN[^], Cookies are disabled by default for security reasons. Use WebClient instead.
|
|
|
|
|
Can you pass the cookie value into the silverlight app as an initial parameter?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
the thing is i want the value out of Silverlight to aspx
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 have a SL site that is structured like
Corporate
- Company1
- Company2
- Company3
- Company4
Entry to the site is www.corporate.com
Each company now wants to basically skin their area of the site with thier company identity and to access their area directly skipping the corportate.com page. I know I can change skins (never having built a skin this is an assumption) so what is the recommended method of going directly to the company pages based on the URL.
All will use the same xbap, wcf and database it is just the entry point for the companies.
Never underestimate the power of human stupidity
RAH
|
|
|
|