Wednesday, May 28, 2008
Honeymoon Gift Basket, Hawaii
At the last PDC I've yet seen all the sessions online.
Now I'm here LIVE!
topics will be:
- The Live Developer Platform, including the MESH.
- Cloud Computing "! From computation, to storage and much more
- Visual Studio 10" and
NET Framework 4.0 -. V.next including ASP.NET Futures of MVC, Ajax and Dynamic Data
- Silverlight Futures, including for Silverlight business applications
- And much, much more.
Thursday, May 8, 2008
Mom Sleeping Nylon Feet
The StackPanel in WPF Controls can arrange with each other.
The property Orientation = horizontal, it is possible to order the elements from left to right.
But there is no property stack items from = "Top ItemControl but requires a panel to represent the objects can be. The default is a StackPanel.
about the items property panel, we can define a ItemsPanelTemplate to specify the other derived from Panel "panel", in which now the items are arranged.
look like the objects determines a DataTemplate. For each item the ItemsControl generates a container (ContentPresenter for ListBox -> ListBoxItem). Since one of these containers can not be directly accessed, defines the ItemsControl a property to the style of the "ItemContainer Set can.
turvy world
To now order the items from the bottom up instead of top to below, as it makes the StackPanel, we need another panel. A DockPanel is suitable because there is more than one possibility, to arrange elements in it. (Top, Left, Right, Bottom).
Now we have to define in ItemContainerStyle that the items should be disposed of in each case below.
ItemsControl
>
\u0026lt; ItemsControl.ItemsPanel
>
< ItemsPanelTemplate
>
< DockPanel
VerticalAlignment
LastChildFill
="False" /> </ ItemsPanelTemplate
>
</ ItemsControl.ItemsPanel
>
< ItemsControl.ItemContainerStyle
>
< Style
>
< Setter
Property
Value
="Bottom"/> </ Style
>
</ ItemsControl.ItemContainerStyle
>
< Button
>
</
Button > < Button
>
\u0026lt;/
Button > \u0026lt; Button
>
\u0026lt;/
Button > \u0026lt;/ ItemsControl
>
Et Voila
How To Catch Rayquaza Shiny Easier
Sometimes it is appropriate to after an object has registered with a property attached, perform some initialization. Here, in the set method by placing the attached property, such as an initialization method will be called.
SetAttachedProperty (
value)
{
obj.SetValue (attached property, value);
The Set method does nothing more than calling for the passed DependencyObjekt
. The actual value of the attached property is set so as a normal DependencyProperty. Just imagine Just imagine a DependencyProperty is nothing but a key is stored with a value in a Dictionary. Each DependencyObject has such a dictionary. The values can also be queried by other objects and set.
To set an attached property, it actually made only the DependencyProperty object on your own to share, not the container object by
! This also means that the initialization is no longer called, because the attached property is set on a different path. Now you can make it to the Convention in the course in an API requires that AttachedProperties must be set always set [property]
. So the plan is XamlReader instructed that if he attached a property in the markup recognizes a corresponding set method is available that can call it.
Nevertheless, it is better to perform an initialization different. How? Through a callback mechanism. Each DependencyProperty has metadata that allow code and callbacks for validation, deposit changes, etc.. A change as the value of a DependencyProperty, then the callback is called and initialization can be performed. This mechanism operates independently was set as a DependencyProperty.
public static
property with call back;
/ / Define the metadata callback
PropertyMetadata
new
PropertyMetadata ();
metadata.PropertyChangedCallback + = OnPropertyWithCallbackChanged;.
/ / register the DependencyProperty
property with callback = DependencyProperty
"property with call back"
,
typeof ( int ) , typeof (Window1
), metadata);
/ / The callback calls the real Initializierungsmethode
private
static
void
OnPropertyWithCallbackChanged (
DependencyPropertyChangedEventArgs value)
{
InitializeProperty ();}
Wednesday, May 7, 2008
Khao San Road Bikini Wax
The grid is the most powerful and most frequently used panels in WPF.
The property ShowGridLines Show Guides.
ShowGridLines
Unfortunately you can not determine how these lines look like himself. Or anything yet?
What actually happens when the grid is set ShowGridLines = True?
The grid line renderer is derived from DrawingVisual. DrawingVisual UIElement and thus have the same ancestor, "Visual". DrawingVisuals are much more efficient than UIElement, because it directly on the "screen" (WPF subsystem) are distinguished.
shows the VisualTree in XamlPad that to be logical Child - a button - found in the hierarchy - have a visual element - the grid line renderer is.
Option 1: A separate grid line renderer Leave
My first idea was to write your own grid line renderer. True to the model of the place in the grid renderer.
The problem is that it is not possible the renderer in the VisuallTree the grid insert. The method that would make this possible - AddVisualChild - is in fact protected. create
A separate grid, draw only the grid lines to me but was too expensive.
There must be a other way of expressing.
Option 2: Write a GridLinesAdorner
If there is no way to change from a UIElement inside without a separate control to derive, so you have to try it just from the outside. The so-called make Adorner.
Adorner "decorate" a UIElement. How that determines the Adorner. It is important that a Adorner will always be drawn to a UIElement. That is, the Adorner hidden beneath drawings.
GridLinesAdorner
Inherits Adorner
Private Grid As
System.Windows.Controls.Grid
'surrender to the ornamental element (in this grid)
New (
ByVal grid As
MyBase . New (grid)
. Grid grid =
Private _pen
As Pen
'pen and draw the lines can be
Property Pen () As
Pen
Get
_pen
Get
Set (ByVal
value
As Pen)
_pen = value
End
End
Property
'draw the lines
Protected Overrides Sub
OnRender (
ByVal dc As
System.Windows.Media.DrawingContext)
If Pen Is Nothing
Exit Sub
If Grid.ColumnDefinitions.Count > 0
Then
Dim
x As
Double
For i As
Integer = 1 To
x = Grid.ColumnDefinitions(i).Offset
dc.DrawLine(Pen, New Point(x, 0),
New Point(x, Grid.ActualHeight))
Next
If
If grid.RowDefinitions.Count > 0
Then
Dim
y As
Double
For i As
Integer = 1 To
y = Grid.RowDefinitions(i).Offset
dc.DrawLine(Pen, New Point(0, y),
New Point(Grid.ActualWidth, y))
Next
If
End
Sub
End
Class
OnRender now leads the way by drawing the grid lines. On the row and column definitions of the grid, the offset of each column are retrieved from the Grid. These serve as coordinator for the corresponding lines at these points to draw. bring
Applying Adorners
To Adorner used, we now need to adapt the code-behind file. Unfortunately, it is not possible to apply directly Adorner in XAML. (The class AdornerDecorator is only there for a layer to provide a decorative element on which a Adorner can be used, but not for the sender itself Adorner)
Private Sub
Window1_Loaded (ByVal
As
Object, ByVal e
As System.Windows.RoutedEventArgs) Handles Me .
Loaded 'layer for the element to get drawn in which the Adorner is
Dim layer As
AdornerLayer = AdornerLayer.GetAdornerLayer ( Me
. Grid)
'Adorner create with pen
Adorner As
New GridLinesAdorner (Grid)
adorner.Pen = New Pen (Brushes.Black, 2)
'Adorner the Add Layer
layer.Add (Adorner)
End
End
Class
The result
is drawn on the grid. Therefore, the edges of the grid located buttons are not visible completely. here will still need an appropriate margin to be applied to the buttons to allow the correct distance from the grid inside.