Following are the topics which are covered:
Explanation: ElementHost control is used to host a WPF element into Windows Forms project. One of its important property is a Child property which indicates type of WPF control to be hosted by the ElementHost control.
If the WPF control which is hosted is the part of the solution as that of the Windows Project then Child property can be set in the Property Grid else Child property must be an instance of WPF control in code.
Step1: Create a Windows Forms application. Then Drag and Drop and ElementHost control on the form.
Step2: In the same solution, Add a WPF Application. By Default a Usercontrol1.xaml file is already added to the project. In this xaml file add the below code:
<TextBlock Text="My WPF UserControl"></TextBlock>
Step3:Build the WPF application and the reference of this WPF application dll in the WindowsForms Application
Step4: In the Windows Forms Application, Open Form1.cs file and add the below code in the Form1 constructor as shown. this will add WPF user control as child element of the ElementHost control.
public partial class Form1 : Form
//add preexisting WPF user controls to your Windows Forms project by using the ElementHost control.
//ElementHost control hosts a WPF element
WinControlsInWPFDemo.UserControl1 uc = new WinControlsInWPFDemo.UserControl1();
elementHost1.Child = uc;
Step4: Now Make Windows Application as Start up project and run the application. This will display the WPF usercontrol as part of windows form.
3.Resource Files , Merged Dictionaries
4.Click Once Deployment
6.TreeView - Get data from xml, Class, Hierarchy Data
7.ListBox - selected item bind to label
12. Assembly Manifest file
13. Settings.Setting file - User and Application settings
To change the value of a user setting, We need to assign it a new value, Then call the Save method as shown below:
Properties.Settings.Default.TestSetting= "This is test";
Here TestSetting is a property in the settings file.
The difference between user setting and application setting is as follows:
A User Setting is user specific whereas Application Setting is constant for all users of the application.
A User Setting can be set at run time whereas Application Settings are read only at run time.
A user setting can vary from user to user whereas application setting is common for all users.
We can store following information in setting file:
web server address
color scheme of an application
Settings can be accessed through the Properties.Settings.Default object
Settings are strongly typed
method to save the new value.
14.styles - basedOn, Precedence
15.Dynamic Resource, Static Resource
16.Difference between Layout controls: Uniform Grid, StackPanel(scrolling), Grid, Canvas(Positioniong)
18.MediaPlayer, MediaElement,Sound Player
23.Adding/Removing elements from Grid
28.SetupProjects - Registry entry, FileEditor, Installer
29. WPF Tree Visualizer
30.Code Access Security
32.Implementing DragandDrop functionality
33. Async Processing - ProgressBar, Dispatcher, ThreadWorkQueueItem
34. Parallel Programming
36.DataGridView custom painting
37.Binding to Nullable value
39.ControlTemplates, DataTemplates, TemplatedParent
42.GroupBox, ComboBox : List Based controls which contains an Items collection to organize items.
ListBox: User can selec t one or more controls
ComboBox: provides user an option to type an entry in the combobox or select one or more controls.
43. Finding resource at run time : FindResource method is used to find resource at runtime and it takes key of the resource as a parameter to find the resource:
<LinearGradientBrush x:Key="gradBrush" StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="White" Offset="0"></GradientStop>
<GradientStop Color="Black" Offset="1"></GradientStop>
<Button Name="btn4">Button 4</Button>
</StackPanel>btn4.Background = (Brush)this.FindResource("gradBrush ");
44.Transforms - Render Transform, Layout Transform
RenderTransform: The Transform is applied after all the other elements have been laid out.
LayoutTransform:The Transform is applied when laying out all the other elements.
Flip using ScaleTransform. Below example Flips a button horizontally:
<Button Height="40" Width="110" VerticalAlignment="Bottom">
To flip an element but maintain its original position, We need to set the element’s RenderTransformOrigin property to .5,.5, as shown here in bold:
<Button RenderTransformOrigin=".5, .5" Height="70" Width="110"
</Button.RenderTrav nsform>Flipped Button
45.packuri syntax :
a. Pack URI syntax is generally used if we want to access resources from other assemblies and locations.
b. For example the following code uses a pack URI syntax to specify the source to be used for a n image.
In the below example, Desert.jpg file is present in the root of the application.
Uri uri1 = new Uri("pack://application:,,,/Desert.jpg");
img2.Source = new BitmapImage(uri1);
In the below example, Desert.jpg file is present in the Images folder of the application.
//Uri uri1 = new Uri("pack://application:,,,/Images/Desert.jpg");
In the below example, Desert.jpg file is present in ResourcesDemo assembly.
Uri uri2 = new Uri("pack://application:,,,/ResourcesDemo;component/Desert.jpg");
img2.Source = new BitmapImage(uri2);
Following are the topics which are covered: