Some WPF Tip/Tricks For the Beginners
For the souls confused about WPF.
Accessing the Global variables in one Window/Page from another in WPF.
This was the first problem I found in my migration from WinForms to WPF.
In WinForms, what we usually do is
frmFormName.GlobalVar1=value 'From another form
In WPF, this fails miserably.
The workaround is
'In the required window - say MainWindow class
Dim VarToChange as Integer 'Can be any type.
Public Property VarNameDesc as Integer 'Type should be same as VarToChange's Type
Get
Return VarToChange
End Get
Set(ByVal value As Integer) 'Here too.
VarToChange=value
End Set
Now, you can access/change it from another window by using MainWindow.VarNameDesc
.
Using a UserControl UC1 from your existing project
Adding a custom control or UserControl to the Toolbox has the following limitations.
Works only for custom controls defined outside the current project.
Does not update correctly when you change the solution configuration from Debug to Release, or from Release to Debug. This is because the reference is not a project reference, but is for the assembly on disk instead. If the control is part of the current solution, when you change from Debug to Release, your project continues to reference the Debug version of the control.
In addition, if design-time metadata is applied to the custom control and this metadata specifies that the ToolboxBrowsableAttribute is set to false, the control does not appear in the Toolbox.
Source : http://msdn.microsoft.com/en-us/library/bb514128.aspx[^]
After some meddling with the XAML File, the workaround was adding this to the Window tag :
xmlns:my="clr-namespace:ProjectName"
Actually, a dropdown will let you choose.
Then, I found this link (Wish I had seen it before!) : http://msdn.microsoft.com/en-us/library/bb514546.aspx[^].
The Obsolete OuterGlow BitmapEffect
Visual Studio warned me that BitmapEffect
became Obsolete. I wanted the OuterGlow effect actually. The DropShadowEffect
with ShadowDepth
set to 0 did the job.
Dim og As New DropShadowEffect
og.ShadowDepth = 0
og.BlurRadius = 11 '10-14 do a good job.
og.Color = Colors.Gold
btnDemo.Effect = og 'A Button's Name
Using Windows Forms Controls
I actually needed a DateTimePicker (WPF in .NET 3.0). Since it is introduced only in later versions, I used the WindowsFormsHost control.
Typing <wf:
will automatically show the list.
Make sure to include the following in the Window tag :
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"