-
Nov 10th, 2013, 11:14 AM
#1
Thread Starter
Lively Member
[VS2012]Some Basic questions about WPF forms
Hello
I am new to WPF (first day today) , i have nice experience with windows forms with Vb , now i am starting wpf forms with VB (I dont know much XAML yet) but i feel like we can do all with code and drag and drop on form and changing properties
Q1] I learnt about doubleanimation class , but the animation i am making is not smooth , its flickering
Code:
Private Delegate Sub Check()
Private Sub dropdown_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles dropdown.MouseLeftButtonDown
Me.Background = New SolidColorBrush(Windows.Media.Color.FromRgb(64, 63, 63))
Dim t As System.Threading.Thread = New System.Threading.Thread(AddressOf Resize)
t.Start()
End Sub
Private Sub Resize()
If Me.Dispatcher.CheckAccess() = True Then
If Not Me.Height = sh Then
Dim da As New DoubleAnimation
da.From = 30
da.To = sh
da.Duration = New Duration(TimeSpan.FromSeconds(0.3))
Me.BeginAnimation(MainWindow.HeightProperty, da)
Else
Dim da As New DoubleAnimation
da.From = sh
da.To = 30
da.Duration = New Duration(TimeSpan.FromSeconds(0.3))
Me.BeginAnimation(MainWindow.HeightProperty, da)
End If
Else
Me.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, New Check(AddressOf Me.Resize))
End If
End Sub
it is code i am using for resizing form with animation , but it flickers a lot , its not smooth , (it looks a bit smooth if i increase animation duration to 7sec or more) i want to fix it
Q2] Docking and align , in vb we directly have a dock property , and even align which auto aligns labels and textbox to center of form when form is resized , here i tried using margin but i don't know what will be its margins in order to keep center when form is resized (i tried using properties but its not working in my case , i maybe doing something wrong ) , when i resize the label doesn't change place and get to center
my current form XAML code is
HTML Code:
<Window x:Name="Main_Bar" x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="347.735" Width="624.676" Margin="0" Background="#01000000" Foreground="#01000000" ResizeMode="NoResize" AllowsTransparency="True" WindowStyle="None">
<Window.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF020202" Offset="1"/>
</LinearGradientBrush>
</Window.OpacityMask>
<Window.TaskbarItemInfo>
<TaskbarItemInfo/>
</Window.TaskbarItemInfo>
<Canvas x:Name="canvas" HorizontalAlignment="Left" VerticalAlignment="Top">
<Label x:Name="dropdown" Width="625" Height="29" Background="#FF403F3F"/>
<DockPanel x:Name="dock1" Height="310" Width="625" HorizontalAlignment="Right">
<Label x:Name="lbl_time" Content=" 00:00 AM" RenderTransformOrigin="0.499,0.441" VerticalAlignment="Top" Foreground="#FFFDFAFA" FontWeight="Bold" FontFamily="Nougat" FontSize="20" HorizontalContentAlignment="Center" DockPanel.Dock="Top"/>
</DockPanel>
</Canvas>
</Window>
Q3] What a canvas is ? , why i need canvas to put more than 2 controls at same time ?
I deleted canvas and added a label , it got added , then i tried to add a button , the label disappears , like its deleted
Q4] can i import all the libraries that i could in normal Vb .NET 4.0 windows forms ?
Q5] Can i give glass effect (Gaussian blur ) to a full transparent form ? i tried but it doesn't seem to work , idk why but i could click even in back application through my form , like form doesn't even exist
Q6] What is that Storyboard thing ? can i use same with vb code ?
Q7] And can u tell me where i can learn manipulating WPF forms through vb code , not through XAML ? or i don't have a option and need to learn XAML?
Unrelated to WPF ] Q8] How can i permanent dock my application on desktop screen , like taskbar ?
Thank You
Bianrybot
-
Nov 10th, 2013, 07:29 PM
#2
Re: [VS2012]Some Basic questions about WPF forms
Please don't call it a form, it's a WPF window! The GUI technology is either WPF or Forms, and that's a separate thing from the coding language you use (VB, Csharp, XAML etc.)
q1.Animating a property like the height of a WPF Window usually happens smoothly. Why are you doing it it in a separate Thread? What happens when you try without it?
q2. You need some kind of container if you want to arrange multiple controls on a window. The Grid container is provided by default, but I find the StackPanel easier to use. A simple way of "docking" a control into its parent container is to delete the Width from the XAML and set the HoriziontalAlignment to Stretch; and/or delete Height and set VerticalAlignment to Stretch. A DockPanel provides more possibilities but I don't have much experience with it
.
q3. The Canvas is a container which allows free placing of its child controls. I suspect that you don't need it for your present purposes. You should make your main container (e.g. the DockPanel) a child of the Window itself.
q4. You can reference any or the libraries from the DotNet Framework, and you can import namespaces from the libraries referenced. Importing is optional, it just saves cluttering your code with long reference paths.
q5. WPF effects like Blur apply to rendering the Visual Tree or parts of it: i.e. brushes, controls etc. It doesn't affect the Desktop because that is in a separate layer. Transparent just means that nothing is painted, so there is nothing to blur. To get the effect you want, I think you would have to capture the area of the desktop behind your window and use it as a brush to paint the background. I can't give you more details, and there may be other/better ways.
q6. The Storyboard class provides a way to script more complex animations. You can animate multiple properties simultaneously or in sequence, and take advantage of easing in/our modes. See also q7.
q7. Most people use WPF for building GUIs for applications, and XAML provides a convenient way to do things like layouts, binding and triggering. In theory, you could do practically all the same things in VB.Net. But it's hard to find usable WPF examples on the web if you don't learn at least the basics of XAML. One of the best places to learn VB.Net equivalents of XAML is (surprisingly) MSDN, since it often gives examples in XAML followed by VB.Net and Csharp equivalents. See the Storyboard Overview for a good example.
q8. Maybe someone else can help you with that. I think it will depend on the OS version.
BB
-
Nov 11th, 2013, 07:58 AM
#3
Re: [VS2012]Some Basic questions about WPF forms
#7 - what do you mean by manipulate? Creating controls at runtime?
I build lots of controls in code - but I still make a container for them in the XAML file. Sometimes I even make "templates" in the XAML that the code calls upon when making controls.
-
Nov 12th, 2013, 06:44 AM
#4
Thread Starter
Lively Member
Re: [VS2012]Some Basic questions about WPF forms
@szlamany
well i meant that , i want to control whole wpe window through vb code only , is there a way i can do it ? so that i skip learning XAML ( as i can do all things with help of vb code , i wont need to learn xaml and write triggers etc in that xaml code )
Edit:- @boops boops
even i don't use a separate thread it flickers by same amount (i tried now) , do i need a graphic card in order to make it work properly ? im using a laptop with i3 M380 and Intel i3 HD graphics , im on windows 7 Ultimate with aero on , all aero animations works perfectly though
Last edited by Binarybot; Nov 12th, 2013 at 07:00 AM.
-
Nov 12th, 2013, 07:17 AM
#5
Re: [VS2012]Some Basic questions about WPF forms
Well...
I see you questioning docking. That's kind of something that WPF does different - imo - from a standard winform. Although I'm sure you can emulate it closely with various xaml tricks.
WPF is different in that it's kind of like DIV's in HTML. Everything is a container of sorts that can hold other things that float around as device size changes or form size changes or whatever.
I draw my own calendar by creating the controls in CODE - and plopping them into XAML defined containers.
Very much like I would if I was using jQuery to manipulate the DOM of an HTML document in a browser.
-
Nov 12th, 2013, 08:32 AM
#6
Thread Starter
Lively Member
Re: [VS2012]Some Basic questions about WPF forms
so...
i just made a performance report by VS2012 Pro , performance analyser , i just used that height increase and decrease function with animation
and this is what is says
1)Warning 1 DA0003: TotalSamples = 11,818.00; You have a high proportion of samples in Kernel Mode. This might indicate a high volume of I/O activity or a high rate of context switching. Consider profiling your application again using Instrumentation Mode. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
2)Message 2 DA0025: % Privileged Time / % User Time = 3.37; Relatively high amount of kernel mode CPU time was measured. You should investigate the source with SysCall sampling enabled. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
3)Message 3 DA0501: (Average)% Processor Time = 15.31; Average CPU consumption by the Process being profiled. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
4)Message 4 DA0502: (Maximum)% Processor Time = 43.00; This rule is for information only. The Process()\% Processor Time counter measures CPU consumption of the process you are profiling. The value reported is the maximum observed over all measurement intervals. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
5)Message 5 DA0503: (Average)Working Set = 5,57,87,204.92; This information was gathered for information only. The Process Working Set counter measures physical memory usage by the process you are profiling. The value reported is the average computed over all measurement intervals. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
Message 6 DA0504: (Maximum)Working Set = 8,46,56,128.00; This rule is for information only. The Process Working Set counter measures physical memory usage by the process you are profiling. The value reported is the maximum observed over all measurement intervals. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
Message 7 DA0505: (Average)Private Bytes = 7,23,53,739.49; This information was gathered for information only. The Process Private Bytes counter measures virtual memory allocated by the process you are profiling that cannot be shared with other processes. The value reported is the average computed over all measurement intervals. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
Message 8 DA0506: (Maximum)Private Bytes = 10,44,60,288.00; This rule is for information only. The Process Private Bytes counter measures virtual memory allocated by the process you are profiling that cannot be shared with other processes. The value reported is the maximum observed over all measurement intervals. C:\Users\Hack-for-Fun\Documents\Visual Studio 2012\Projects\Windows Status Bar\Windows Status Bar131112.vsp 0 0
first i dont know why it should eat 57mb to 104 mb of ram for such a small program ( is should say it has nothing yet)
my full code is :-
Code:
Imports System.Threading.Thread
Imports System.Windows.Media.Animation
Class MainWindow
'save working area locations
Dim sw, sh As Integer
#Region "Form Subs"
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Me.Left = 0
Me.Top = 0
Me.Width = My.Computer.Screen.WorkingArea.Width
Me.Height = 30
sw = My.Computer.Screen.WorkingArea.Width
sh = My.Computer.Screen.WorkingArea.Height
'set controls to proper positions
End Sub
Private Sub MainWindow_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged
dropdown.Width = Me.Width
End Sub
#End Region
#Region "dropdown"
Private Sub dropdown_MouseEnter(sender As Object, e As MouseEventArgs) Handles dropdown.MouseEnter
Dim da As New DoubleAnimation
da.From = 0.3
da.To = 1
da.Duration = New Duration(TimeSpan.FromSeconds(1))
dropdown.BeginAnimation(Label.OpacityProperty, da)
End Sub
Private Sub dropdown_MouseLeave(sender As Object, e As MouseEventArgs) Handles dropdown.MouseLeave
Dim da As New DoubleAnimation
da.From = 1
da.To = 0.3
da.Duration = New Duration(TimeSpan.FromSeconds(1))
dropdown.BeginAnimation(Label.OpacityProperty, da)
End Sub
Private Delegate Sub Check()
Private Sub dropdown_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles dropdown.MouseLeftButtonDown
Me.Background = New SolidColorBrush(Windows.Media.Color.FromRgb(64, 63, 63))
' Dim t As System.Threading.Thread = New System.Threading.Thread(AddressOf Resize)
't.Start()
If Not Me.Height = sh Then
Dim da As New DoubleAnimation
da.From = 30
da.To = sh
da.Duration = New Duration(TimeSpan.FromSeconds(3))
Me.BeginAnimation(MainWindow.HeightProperty, da)
Else
Dim da As New DoubleAnimation
da.From = sh
da.To = 30
da.Duration = New Duration(TimeSpan.FromSeconds(3))
Me.BeginAnimation(MainWindow.HeightProperty, da)
End If
End Sub
End Class
what im doing wrong , so that its consuming all resources and eating average 15% of cpu whole time , can anyone tell me what does this performance report says and how to fix it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|