Wednesday, May 28, 2008

Honeymoon Gift Basket, Hawaii

PDC2008 I'm coming

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

StackPanel items in reverse order View

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.




\u0026lt;


ItemsControl

>


\u0026lt; ItemsControl.ItemsPanel
>


< ItemsPanelTemplate
>


< DockPanel
VerticalAlignment

="Top"

LastChildFill
="False" />
</ ItemsPanelTemplate
>


</ ItemsControl.ItemsPanel
>


< ItemsControl.ItemContainerStyle
>


< Style
>


< Setter
Property

="DockPanel.Dock"

Value
="Bottom"/>
</ Style
>


</ ItemsControl.ItemContainerStyle
>


 

<
Button

>

1

</
Button
> < Button
>

2

\u0026lt;/
Button
> \u0026lt; Button
>

3

\u0026lt;/
Button
> \u0026lt;/ ItemsControl
>

Et Voila

How To Catch Rayquaza Shiny Easier

AttachedProperties properly initialize

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 (

DependencyObject obj, int

value)
{
obj.SetValue (attached property, value);

InitializeProperty ();}



The Set method does nothing more than calling for the passed DependencyObjekt

SetValue

. 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

set [property]

! 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

ReadOnly


DependencyProperty

property with call back;

/ / Define the metadata callback

PropertyMetadata

metadata =

new

PropertyMetadata ();

metadata.PropertyChangedCallback + = OnPropertyWithCallbackChanged;.

/ / register the DependencyProperty


property with callback =
DependencyProperty

RegisterAttached (

"property with call back"
,


typeof ( int ) , typeof (Window1
), metadata);


/ / The callback calls the real Initializierungsmethode
private


static

void
OnPropertyWithCallbackChanged (

DependencyObject obj,

DependencyPropertyChangedEventArgs value)
{
InitializeProperty ();}


Wednesday, May 7, 2008

Khao San Road Bikini Wax

own lines in Grid Panel draw


The grid is the most powerful and most frequently used panels in WPF.

The property ShowGridLines Show Guides.

Grid

ShowGridLines

= "True">



These lines serve only as an aid for the developer, who can thus detect the position of columns and rows.


Unfortunately you can not determine how these lines look like himself. Or anything yet?

What actually happens when the grid is set ShowGridLines = True?

WPF Controls can distinguish itself, in which they OnRender method override. As is the case with OnPaint in WinForms.


But the Grid is not made use of to draw the lines! Instead, the logical UI elements in the panel, an additional visual element of "grid line renderer added. This does not happen by ControlTemplate. (Templates also change the look so the VisualTree), special programmatically by calling AddVisualChild (visual) in the base class.


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.


Public


Class

GridLinesAdorner


Inherits Adorner


Private Grid As
System.Windows.Controls.Grid



'surrender to the ornamental element (in this grid)


Sub


New (
ByVal grid As

System.Windows.Controls.Grid)



MyBase . New (grid)

Me

. Grid grid =

End Sub





Private _pen
As
Pen



'pen and draw the lines can be


Public


Property Pen () As
Pen


Get

Return

_pen

End


Get


Set (ByVal
value
As Pen)

_pen = value
End

Set



End
Property




'draw the lines




Protected Overrides Sub
OnRender (

ByVal dc As
System.Windows.Media.DrawingContext)

If Pen Is Nothing

Then


Exit Sub

 

If Grid.ColumnDefinitions.Count > 0
Then


Dim
x As
Double


For i As

Integer
= 1
To

Grid.ColumnDefinitions.Count - 1


x = Grid.ColumnDefinitions(i).Offset
dc.DrawLine(Pen, New Point(x, 0),
New
Point(x, Grid.ActualHeight))


Next

End


If

 

If grid.RowDefinitions.Count > 0
Then


Dim
y As
Double


For i As

Integer
= 1
To

Grid.RowDefinitions.Count - 1


y = Grid.RowDefinitions(i).Offset
dc.DrawLine(Pen, New Point(0, y),
New
Point(Grid.ActualWidth, y))


Next

End


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)


Class Window1




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

Dim

Adorner As

New
GridLinesAdorner (Grid)


adorner.Pen = New Pen (Brushes.Black, 2)

'Adorner the Add Layer


layer.Add (Adorner)



End

Sub



End

Class


The result



who still surrounded by a frame around the grid would like to have, the need to pack only the grid in a border.


Note: As you can see the Adorner


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.