WPF Canvas, how to add children dynamically with MVVM code behind

ItemsControl is your friend: <Grid> <Image Source=”…”/> <ItemsControl ItemsSource=”{Binding Points}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property=”Canvas.Left” Value=”{Binding X}”/> <Setter Property=”Canvas.Top” Value=”{Binding Y}”/> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush=”Red” BorderThickness=”1″ Width=”{Binding Width}” Height=”{Binding Height}”/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> The above assumes your VM exposes a collection of points via a Points property, and … Read more

How to select first child?

In plain JavaScript you would use something like: // Single document.querySelector(“.onediv”).classList.add(“red”); // Multiple (deeply nested) document.querySelectorAll(“.onediv:first-child”).forEach(EL => EL.classList.add(“red”)); Or by Parent Element using Element.firstElementChild: // Single Parent document.querySelector(“.alldivs”).firstElementChild.classList.add(“red”); // Multiple parents document.querySelector(“.alldivs”).forEach(EL => EL.firstElementChild.classList.add(“red”)); jQuery get first child Use: $(“.onediv”).eq(0) Other examples of selectors and methods targeting the first LI inside an UL: Syntax Type … Read more

How can I get the child windows of a window given its HWND?

Here you have a working solution: public class WindowHandleInfo { private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam); [DllImport(“user32”)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam); private IntPtr _MainHandle; public WindowHandleInfo(IntPtr handle) { this._MainHandle = handle; } public List<IntPtr> GetAllChildHandles() { List<IntPtr> childHandles = new List<IntPtr>(); GCHandle gcChildhandlesList = GCHandle.Alloc(childHandles); IntPtr … Read more

tech