Why are ActualWidth and ActualHeight 0.0 in this case?

ActualHeight and ActualWidth are not set until the control is measured and arranged. Usually there is nothing in InitializeComponent() that causes a measure, so when it returns these will still be zero. You can force these to be computed earlier by simply calling the window’s Measure() and Arrange() methods manually after the window’s InitializeComponent() returns. … Read more

DependencyProperty getter/setter not being called

I would suggest not to use ObservableCollection as the type of an Items dependency property. The reason for having an ObservableCollection here (I guess) is to enable the UserControl to attach a CollectionChanged handler when the property value is assigned. But ObservableCollection is too specific. The approach in WPF (e.g. in ItemsControl.ItemsSource) is to define … Read more

How to dynamically add RowDefinition or ColumnDefinition to a Grid with binding?

You can use attached properties for a Grid that modify the RowDefinitions and ColumnDefinitions when those properties are set or changed. It will allow you to write your Grid like this: <Grid local:GridHelpers.RowCount=”{Binding MaxGridRow}” local:GridHelpers.ColumnCount=”3″ /> Then just expose a property from your ViewModel which returns the largest row number in the Cells collection. You … Read more

Wanting a type of grid for a pixel editor

More than a few hundred components is awkward. One easy way to get big pixels is to use drawImage() and scale the mouse coordinates as shown here and here. Here’s a simple example. import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.image.BufferedImage; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JPanel; … Read more

How to populate a WPF grid based on a 2-dimensional array

The purpose of the Grid is not for real databinding, it is just a panel. I am listing down the easiest way to accomplish the visualization of a two dimensional list <Window.Resources> <DataTemplate x:Key=”DataTemplate_Level2″> <Button Content=”{Binding}” Height=”40″ Width=”50″ Margin=”4,4,4,4″/> </DataTemplate> <DataTemplate x:Key=”DataTemplate_Level1″> <ItemsControl ItemsSource=”{Binding}” ItemTemplate=”{DynamicResource DataTemplate_Level2}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation=”Horizontal”/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate> </Window.Resources> … Read more

How to validate inputs dynamically created using ng-repeat, ng-show (angular)

Since the question was asked the Angular team has solved this issue by making it possible to dynamically create input names. With Angular version 1.3 and later you can now do this: <form name=”vm.myForm” novalidate> <div ng-repeat=”p in vm.persons”> <input type=”text” name=”person_{{$index}}” ng-model=”p” required> <span ng-show=”vm.myForm[‘person_’ + $index].$invalid”>Enter a name</span> </div> </form> Demo Angular 1.3 … Read more