A x = new A( ); A x = new B( ); B x = new A( ); B x = new B( );
object → A → B → ... → WFor the method call x.F( ), how does .Net know which F to call if F is defined in more than one class?
int n = 3; for(int i = 1; i <= 6; i++) { Console.WriteLine(n); n *= n; }
Example files: wpf.zip and wpf.txt.
To open an UTF-8 encoded file for reading:
true means "detect encoding from byte order marks:"
Use the UTF-8 encoding system for Unicode:
Feature | .Net Framework |
Windows Store |
Silverlight | Windows Phone |
Core | X | X | X | X |
LINQ | X | X | X | X |
IQueryable | X | X | X | 7.5+ |
Dynamic Keyword | 4.5+ | X | X | |
MEF | X | X | X | |
NCL | X | X | X | X |
Serialization | X | X | X | X |
WCF | X | X | X | X |
MVVM | 4.5+ | X | X | X |
Data Annotations | 4.0.3, 4.5+ | X | X | |
XLINQ | 4.0.3, 4.5+ | X | X | X |
System Numerics | X | X | X |
MEF: Managed Extensibility Framework
NCL: Network Class Library
WCF: Windows Communication Founcation
MVVM: Model-View-View-Model
<html xmlns="http://www.w3.org/1999/xhtml">
xmlns="http://schemas.microsoft.com/ winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/ winfx/2006/xaml"
{http://schemas.microsoft.com/winfx/2006/xaml}
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:DefaultNamespace"
window1 | button1 | stackPanel1 / \ ellipse1 ellipse2
Property meta-data – The property system knows how a DP should behave based on meta-data supplied at the time the property is registered with the system. This meta-data is not processed using CLR reflection for performance reasons.
XAML friendly DPs can be set in XAML like normal properties.
Value inheritance Any DP can be given the ability to inherit its value from the property setting on an ancestor element. This functionality is similar to ambient properties in WinForms applications. Here are some situations where walue inheritance is useful: propagating a data source down the element tree, font settings, flow direction (right-to-left) settings.
public static readonly DependencyProperty MyNameProperty = DependencyProperty.Register( "MyName", typeof(string), typeof(MyClass), new UIPropertyMetadata( MyClass.MyNameValueChanged));
public string MyName { get { return (string)GetValue(MyNameProperty); } set { SetValue(MyNameProperty, value); } }
private static void MyNameValueChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { MyClass myClass = (MyClass) d; myClass.nameText.Text = (string) e.NewValue; }
ParentElement.AttachedProperty = "AttachedPropertyValue"
<TextBox Canvas.Top="23">and
<Window.Resources> <local:Person x:Key="alice" Name="Alice" Gender="F" Age="11" /> </Window.Resources>
errorProvider1.SetError(textBox1, "Value out of range.");
WPF Control | Java Layout Manager | Example |
---|---|---|
Canvas | None | Controls2 |
WrapPanel | FlowLayout | Controls3 |
UniformGrid | GridLayout | Numbers1 |
Grid | GridBagLayout | Controls4 |
StackPanel | BoxLayout | Controls5 |
DockPanel | BorderLayout |
Mouse Events Events that occur from mouse action such as Click, MouseDoubleClick, MouseUp, MouseMove or MouseMove.
Keyboard Events Events that occur from pressing or releasing keyboard keys such as KeyDown or KeyUp.
Stylus Events Events that occur from stylus action. The stylus takes the place of a mouse on a tablet PC.
window1 | button1 | stackPanel1 / \ ellipse1 ellipse2
Tunneling Events The event fires first in the control's topmost ancestor, then tunnels down to the ancester's child, to its grandchild, and so on until the event reaches the control itself.
e.Handled = true;in a preview event, that event is prevented from firing. Furthermore, the corresponding non-preview event is prevented from firing and bubbling up as well.
<Trigger Property="IsFocused" Value="True"> <Setter Property="Background" Value="Navy" /> </Trigger>
<Window.Resources> <ImageBrush x:Key="brush" ImageSource="c:/Pizza.jpg" /> </Window.Resources>
<Rectangle Name="rectangle1" Stroke="Black" Fill="{StaticResource brush}" />
ResourceDictionary dict = new ResourceDictionary(); ImageBrush brush = new ImageBrush(); brush.ImageSource = new BitmapImage( new Uri("c:/Pizza.jpg")); dict.Add("brush", brush); rect1.Fill = (ImageBrush) dict["brush"];
<TextBox Text="{Binding Path=Value, ElementName=sldTemperature}">"This binding causes the textbox to show a double precision number with 14 digits behind the decimal point. To show fewer digits behind the decimal or to show an integer in the textbox, a Converter object is required.
<Button name="button1"> <Button.RenderTransform> <TransformGroup> <RotateTransform Angle="45" /> </TransformGroup> </Button.RenderTransform> Test Button </Button>