: ? , , . , . , , "" .
... , uxMainContentGrid - , .
<Style TargetType="{x:Type wpflib:RatioPresenterControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type wpflib:RatioPresenterControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}">
<Grid x:Name="uxMainContentGrid">
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
, , .
Public Class RatioItem
Public Property Value As Double
Public Property Brush As Brush
End Class
RatioItems RatioItems.
Public Shared ReadOnly RatioItemsProperty As DependencyProperty = _
DependencyProperty.Register("RatioItems", GetType(IEnumerable(Of RatioItem)),
GetType(RatioPresenterControl),
New FrameworkPropertyMetadata(New List(Of RatioItem), AddressOf OnRatioItemsPropertyChanged))
, , . , . , .
Public Shared Sub OnRatioItemsPropertyChanged(sender As Object, e As DependencyPropertyChangedEventArgs)
If (_MainContentGrid IsNot Nothing) Then
Dim ratioItems As IEnumerable(Of RatioItem) = TryCast(e.NewValue, IEnumerable(Of RatioItem))
ReconstructGridColumns(ratioItems, _MainContentGrid)
End If
End Sub
. , , RatioItems . , , .
Public Overrides Sub OnApplyTemplate()
MyBase.OnApplyTemplate()
_MainContentGrid = TryCast(Me.Template.FindName("uxMainContentGrid", Me), Grid)
ReconstructGridColumns(Me.RatioItems, _MainContentGrid)
End Sub
""...
Private Shared Sub ReconstructGridColumns(ByVal ratioItems As IEnumerable(Of RatioItem), ByVal mainContentGrid As Grid)
Dim newContent As Rectangle
Dim columnCount As Integer = 0
mainContentGrid.ColumnDefinitions.Clear()
For Each item In ratioItems
mainContentGrid.ColumnDefinitions.Add(New ColumnDefinition() With {.Width = New GridLength(item.Value, GridUnitType.Star)})
newContent = New Rectangle() With {.Name = "item" & columnCount, .Fill = item.Brush}
mainContentGrid.Children.Add(newContent)
Grid.SetColumn(newContent, columnCount)
columnCount += 1
Next
End Sub
. . , "" ...:)