|
GDI / GDI+ are not used in Silverlight / WPF. Do NOT use WritableBitmap. It is VERY slow. If you are going to go to Silverlight, throw out your code and do it right. Silverlight is a whole new ball game. You don't do stuff at the pixel level anymore. Silverlight has a bunch of shape primitives that you piece together. Line, circle, rect, etc.
|
|
|
|
|
As I said I'm very new of Silverlight and even WPF so I'm trying to understand wich approach could solve my problem.
From my undestanding you are suggesting me to rewrite my GDI+ calls and all the program logic around using Silverlight Shape library as the better solution. Is that correct?
Take a look at this http://writeablebitmapex.codeplex.com. What do you think about?
|
|
|
|
|
As I said, do NOT use that if you are going Silverlight / WPF. VERY bad idea.
1) it is very slow
2) it defeats the whole purpose of Silverlight / WPF.
You need to understand Silverlight / WPF at the CONCEPTUAL level before you even consider it.
In GDI / GDI+ you piece together / GUIs at the pixel level and it all gets drawn on a single surface / off screen DC / double buffered, etc.
No such concepts in Silverlight / WPF. You piece together GUIs at the OBJECT level (controls & shapes) and you end up with a LAYERED SURFACE.
In GDI you draw a rectangle on screen and then draw another rectangle on top... now you have a flat surface with no idea of whats there. Its just pixels.
In WPF / SL, they remain as layered objects so you can move / resize / show / hide / animate / rotate / etc.
In WPF / SL you do your GUI in pretty much all XAML and only do business logic in the code behind.
So in answer to your question, you don't port GDI code to SL, you dump it and rewrite in XAML .
|
|
|
|
|
This article may be an interesting read - http://niknak.org/blog/631-say-goodbye-to-gdi-on-the-web[^].
AFAIK. there is no automated tool that does this.
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.
|
|
|
|
|
|
Thanks for your samples and thaks to everybody. Very clear the different approaches GDI/Silverlight. OK I have to learn xaml and rewrite my gdi app.
But just a more question: In order to host on a web page a painting App like mine (drow lines, draw images, interact with mouse) and having to re-write the old App in another language/environment, is Silverlight the only right solution or may be Javascript or what else.
Having to experiment one more environment is Silverlight the winning solution?
I understand this is a very generic question, but may be you can help me with your experience.
Thanks
|
|
|
|
|
I have the following class
namespace WpfDataTemplate
{
public class Rung : UIElement
{
public int RungNumber { get; set; }
}
}
and the following XAML
<Window x:Class="WpfDataTemplate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfDataTemplate"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<StackPanel.Resources>
<DataTemplate DataType="{x:Type local:Rung}">
<Grid VerticalAlignment="Top" MinHeight="60" MinWidth="175">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"/>
<ColumnDefinition MinWidth="175"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" x:Name="number" Text="{Binding RungNumber}"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Path x:Name="LeftRail" Data="M0,0 L0,60" Stretch="Fill" Stroke="Blue" Width="1" HorizontalAlignment="Left" Grid.Column="1"/>
<Path x:Name="RightRail" Data="M0,0 L0,60" Stretch="Fill" Stroke="Blue" Width="1" HorizontalAlignment="Right" Grid.Column="1" Margin="0,0,10,0" />
<Path x:Name="Run" Data="M0,0 L10,0" Height="1" Stretch="Fill" Stroke="Blue" Grid.Column="1" VerticalAlignment="Top" Margin="0,30,10,0"/>
</Grid>
</DataTemplate>
<local:Rung x:Key="newRung" />
</StackPanel.Resources>
<StackPanel Height="50" Orientation="Horizontal">
<Button Height="24" Content="Add Rung"/>
</StackPanel>
<ContentControl Content="{StaticResource newRung}"/>
</StackPanel>
</Window>
I want to add a click handler to the button that will add an instance of the class to the MainWindow, but it doesn't work.
private void Button_Click(object sender, RoutedEventArgs e)
{
Rung r = new Rung {RungNumber = 1};
RungSurface.Children.Add(r);
}
Can anyone help?
Thanks,
Jim
|
|
|
|
|
I can't see anywhere in the xaml where the RungSurface in bound.
"You get that on the big jobs."
|
|
|
|
|
I got confused with all the path stuff and the use of the local as a datacontext.
I would think he should change the underlying datacontext, presumably an observablecollection.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I must admit, there are so many ways to do things in xaml, I'm not sure myself but I would have expected something along the lines of:
<StackPanel ...>
<ItemsControl ItemsSource="{Binding RungSurface}"
"You get that on the big jobs."
|
|
|
|
|
I am using Silverlight 4.0. I'm trying to save a block of text to a txt file in Isolated Storage. However when the file reaches exactly 1000 characters, it stops loading and closes itself. Is 1000 characters the maximum file size for a file in isolated storage. What if I have about 5000 characters to store? Am I just missing a setting somewhere?
Thanks
Brent
|
|
|
|
|
|
But does 1000 characters take 1 megabyte to save? It actually takes 1 kilobyte.
My isolated storage variable says I have tons of free space.
The odd thing is that the stream writer doesn't throw an error.
Brent
|
|
|
|
|
Sorry, there was another unrelated error that was interrupting the stream flushing. Fixed it and now I'm getting my entire file.
Brent
|
|
|
|
|
Well. Thanks for posting the solution.
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.
|
|
|
|
|
The following line does not compile in silverlight 4.0
XmlDocument myFile = new XmlDocument();
Note that I do have a reference to system.xml and also using the
using System.Xml namespace
Any thoughts please?
Thanks
|
|
|
|
|
You can't really use XMLDocument.
What you need to do is use XDocument and do something like -
XDocument myFIle = XDocument.Parse(xmlContent);
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.
|
|
|
|
|
I agree that he should probably use the newer classes, he can still use XmlDocument that way if he wants to. See my answer to his question.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Try this. It's an example I found - using google - on the MSDN web site :
using System.IO;
using System.Xml;
using System.Xml.Schema;
private void LoadXmlData()
{
XmlValidatingReader reader = null;
XmlTextReader txtReader = null;
string filename = "myfilename.xml";
try
{
txtReader = new XmlTextReader(filename);
reader = new XmlValidatingReader(txtReader);
reader.ValidationType = ValidationType.DTD;
reader.ValidationEventHandler += eventHandler;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}
void ValidationCallback(object sender, ValidationEventArgs args )
{
}
EDIT ===
I missed the fact that you're using Silverlight. Loading a client-side file can be problematic if nigh impossible (unless you're running out of browser and the file is in a specific place).
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Ah I see. Thanks.
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.
|
|
|
|
|
In my solution, there is a silverlight 4.0 project as well as the web host project.
Question:
From one of the .xaml files i.e. mainpage.xaml which is inside the silverlight project, I would like to access an xml file i.e. test.xml
Which is also inside the silverlight project.
How can I do this please?
Thanks
|
|
|
|
|
Through the code behing you can[^].
I dont think the XAML is powerful enough to load an xml file in SIlverlight.
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.
|
|
|
|
|
While the title is somewhat generic I would love to disucss this as a beginner with experienced MVVM users and other beginners as well.
I have created a WPF app mostly ignoring MVVM, at least to begin with. I have now decided to refactor it and use MVVM. I'm hoping to make it better and easier to manage. However there are several things I'm not 100% certain about how to implement some things in MVVM. I guess there isn't just one way but I would love to hear what you like to do and how. I'm adding numbered discussion points here to better catagorize. If others have questions or thoughts to add please be welcome.
1) Most MVVM examples are quite simple. In reality it can be quite different. For example I often have objects that include a number of other objects which also include other objects. So there is a View where users could choose an object from a list, see detailed info about it and also a list of objects that are it's children. They could then choose a child object and get detailed info about it as well.
How does this apply as ViewModels. Is it a single viewmodel that includes everything, or a viewmodel that opens another different viewmodel. I would like to have the child object as it's own ViewModel/UserControl - View and have the parent able to show this UserControl within it's own.
Would you rather have the child inside the parents viewmodel or seperate but linked?
Can you point out examples or books that investigates this?
2) iEditableObject, I've used this interface on my objects and it works with CollectionViews. I haven't really seen it mention in MVVM. It means a object can basically be in a EditMode and you can rollback changes made and such. Now in my program when you look at the details of a object they are static, meaning you can't change text (it's textBlocks not TextBox), then you press a EDIT button and you get the edit look. I've done this by switching out the dataTemplate for the object. However that seems to mean logic inside Xaml. I guess I could do it in code, or just have seperate UserControls and swithc them out
Also this handles well adding new items to collections but I haven't seen this used in any MVVM example I've seen. Could you point out any?
3) If many apps are getting the data from the same place, and they can change that data. How do you keep the data current. Do you reload it regulary, use ActiveRecord pattern. I guess this has nothing to do with MVVM but I'm fishing out what people have used alongwith MVVM with good results.
4) Can you use LINQ entity items with any good results, like perhaps populating the viewmodel with them? It's not proper to keep the context open but having the object itself might help with saving back to database. What happens to a LINQ object when the Context is closed. Do I still have access to it's relative tables an such.
5) I'm very often showing objects as lists+details for the selected object (master detail view). However the details between objects can be somewhat different. I guess I could make a abstract ViewModel for their common functionality but what about the Views themselves. It will have the same buttons, the same format showing the list and then the details. Basicly the only difference will be the fields in the detail. I can't make a abstract UserControl (except without the XAML). How to solve this? Using styles, ControlTemplates? Again any examples out there I could check out?
I'll probably have million other questions but this is enough for now. If anyone can answer or just point towards something with good answers/examples I would be very happy.
Most of what I know about MVVM comes from http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
|
|
|
|
|
IngoVals wrote: 4) Can you use LINQ entity items with any good results, like perhaps populating the viewmodel with them? It's not proper to keep the context open but having the object itself might help with saving back to database. What happens to a LINQ object when the Context is closed. Do I still have access to it's relative tables an such.
IngoVals wrote: 4) Can you use LINQ entity items with any good results, like perhaps populating the viewmodel with them? It's not proper to keep the context open but having the object itself might help with saving back to database. What happens to a LINQ object when the Context is closed. Do I still have access to it's relative tables an such.
Those are a lot of good questions.
I can only try and share some of my experiences with you. To be honest, I myself would not know if my approaches to these whatever problems I faced were correct or not in the first place.
IngoVals wrote: Would you rather have the child inside the parents viewmodel or seperate but linked?
Keep them separate but linked.
IngoVals wrote: 3) If many apps are getting the data from the same place, and they can change that data. How do you keep the data current. Do you reload it regulary, use ActiveRecord pattern. I guess this has nothing to do with MVVM but I'm fishing out what people have used alongwith MVVM with good results.
You would need some sort of notification mechanism to let all your clients know data has changed. One way could be to use a duplex polling WCF service. Another way could be to use sockets (In case you are not using WCF).
IngoVals wrote: 4) Can you use LINQ entity items with any good results, like perhaps populating the viewmodel with them? It's not proper to keep the context open but having the object itself might help with saving back to database. What happens to a LINQ object when the Context is closed. Do I still have access to it's relative tables an such.
Yes you can. Perhaps someone else here has a better answer to the remaining part of the question.
IngoVals wrote: very often showing objects as lists+details for the selected object (master detail view). However the details between objects can be somewhat different. I guess I could make a abstract ViewModel for their common functionality but what about the Views themselves. It will have the same buttons, the same format showing the list and then the details. Basicly the only difference will be the fields in the detail. I can't make a abstract UserControl (except without the XAML). How to solve this? Using styles, ControlTemplates? Again any examples out there I could check out?
IMO, Keep the views separate.
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.
|
|
|
|
|
Just a heads up from *personal* experience. If you wrote a WPF app without using MVVM, if your project has reached any size at all, its not worth the effort to go MVVM. Non MVVM -> MVVM conversion is usually a complete re-write / re-design. The MFC / Winforms way of doing things is just such a different thought process. Not saying it can't be done, but if you've gone past a couple of views, its pretty much a re-write .
|
|
|
|