|
Dear,
I'm reading Wrox WPF Programmers Reference Windows Presentation Foundation with C# 2010 and .NET 4
In chapter 16 - Themes and Skins I found following code that changes a skin at run time and attaches eventhandler for the different controls.
The Loadskin method is executed each time you select a skin from a context menu 'blue' or 'red'. I was wondering if the garbage collector removes the controls (and their handlers) at some point from memory. As I understood, the controls are re-generated each time, so if they're not collected, that could be a problem.
Note that it does say at some points 'code omitted', but the author did not mention my issue specifically so I doubt it would be there in the full code.
private void LoadSkin(string skin_file)
{
FrameworkElement element =
(FrameworkElement)Application.LoadComponent(new Uri(skin_file, UriKind.Relative));
this.Content = element;
Button btn;
Polygon pgn;
Rectangle rect;
Grid grd;
Ellipse ell;
switch (element.Tag.ToString())
{
case "Red":
btn = (Button)element.FindName("btnRepairDisk");
btn.Click += new RoutedEventHandler(btnRepairDisk_Click);
break;
case "Blue":
ell = (Ellipse)element.FindName("ellMove");
ell.MouseDown += new System.Windows.Input.MouseButtonEventHandler(rectMove_MouseDown);
grd = (Grid)element.FindName("grdExit");
grd.MouseDown += new System.Windows.Input.MouseButtonEventHandler(grdExit_MouseDown);
break;
}
}
thanks.
V.
|
|
|
|
|
Assuming you don't keep references to the controls elsewhere, I believe they would be collected as soon as the GC realized they were no longer a child of "this" (I assume the main window).
This wouldn't happen immediately, though... Just whenever the GC gets around to it.
|
|
|
|
|
Dear,
Thanks for your reply, it was more or less what I thought. Looks to me that it's better to do some cleaning up before changing large skins?
V.
|
|
|
|
|
Unless you plan on doing this frequently (As in, swapping skins automatically every few seconds), it shouldn't be a big deal. When the GC gets around to it, it'll trash any old ones lying around.
|
|
|
|
|
I have a demo about change skin of application. But when start application load style is ok. When I click a button to change style then my application stop. Please help me fix this error.
Here is my demo: http://www.kienthuccorp.com/research/ex.zip. Thank you very much
|
|
|
|
|
U S E T H E D E B U G G E R!!!
It comes with Visual Studio. Free.
Nobody here is going to download a file from someone they don't know.
.45 ACP - because shooting twice is just silly ----- "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 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I have an example about wpf but it has an error. But I can not post or attache my example for everybody can help me. Please help me. Thank you very much.
|
|
|
|
|
You could always upload it to a service such as Windows Live, or Dropbox and then provide a link here.
|
|
|
|
|
Is it just a code snippet? If so, you can just paste it here with Encode "<" (and other HTML) characters when pasting checked. Then you can surround it in a PRE block and specify the lang attribute. With WPF XAML, you'd specify the lang as "XML". For example, typing this:
<pre lang="xml"><Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
</Window></pre>
Will produce this:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
</Window>
And if you had some VB.Net, you'd specify the lang as "VB", like so:
<pre lang="vb">Class MainWindow
Public Sub DoStuff()
Dim x As Integer = 5
End Sub
End Class</pre>
Which would look like:
Class MainWindow
Public Sub DoStuff()
Dim x As Integer = 5
End Sub
End Class
If you click the "Preview" button before you post, you can make sure the code looks as you intended.
|
|
|
|
|
I am displaying date in my .XAML page
In .XAML.VB
e.g
variablename = date.now()
But it is returning my client date. i want to display server date.
One person's data is another person's program.
--J.Walia
|
|
|
|
|
You'd have to call a method on the server side through a WCF call. Be aware, though, that because of latency issues, the value that you receive would be the time that the server received and processed the request, and then by the time the message was transmitted back there would be extra latency involved.
|
|
|
|
|
how i can handle this??
One person's data is another person's program.
--J.Walia
|
|
|
|
|
I already told you. Use WCF.
|
|
|
|
|
For many applications they in fact use the database datetime for being consistent. in Oracle this could be Select getdate() from dual; I believe.
V.
|
|
|
|
|
V. wrote: in Oracle this could be Select getdate() from dual
No it isn't - Oracle uses select sysdate from dual. Why would you consider doing this though? If you have a web server, then the application has access to the server time anyway, why on earth would you expect it to make an unnecessary call to a database. Bear in mind that the db connection might need to be created which is an expensive operation and database connections should not be squandered on trivial tasks like this; it it's a high traffic site then this is an unnecessary waste of resources.
Supplying the date in this format should only be used when attempting to perform an operation on the database, e.g. an insert or update.
|
|
|
|
|
I wasn't 100% sure about the select statement, it might very well have been select sysdate from dual;
You can argue about the design, but the concept of taking the database datetime does exist. I never said I was pro or con. If you use more then 1 webserver you also need additional setting up for making sure the time is equal (granted this can be done via time synchro eg).
V.
|
|
|
|
|
Is there a way to change the cursor for every control at once? Or do I have to visit every single control and flip each one individually. I have a stackpanel, but changing the cursor on the stackpanel doesn't affect any of the controls in the stackpanel. The treeview in the stack panel has numerous checkboxes, images and other things. It seems impractical that I have to set the cursor on each control.
Thanks
Brent
|
|
|
|
|
Try using Mouse.OverrideCursor .
|
|
|
|
|
I'm sorry I forgot to mention I'm in Silverlight which apparently doesn't have Mouse.OverrideCursor, unless I'm missing a reference.
Brent
|
|
|
|
|
|
Thanks to your prior post, I had just Googled into that same page when I got your response.
Thanks
Brent
|
|
|
|
|
|
Hi, I am looking for a framework that runs for .NET 3.5 or better for 4.0 that support pluggable gadget system for windows user interface development. I want to develop a main container window application that can load gadgets that I or my team develop. User could manage gadget like google home page..add gadget and set layout. Also there must be interface to talk each gaget with the container static components or other gadgets. Is there a framework that is written open source or paid api?
karanba
|
|
|
|
|
You could always look at using Prism[^] for this.
|
|
|
|
|
You should look into MEF/MAF. Choosing among MAF or MEF is left with you.
http://mef.codeplex.com/
HTH
|
|
|
|