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

A dynamic buffer type in C++?

You want a std::vector: std::vector<char> myData; vector will automatically allocate and deallocate its memory for you. Use push_back to add new data (vector will resize for you if required), and the indexing operator [] to retrieve data. If at any point you can guess how much memory you’ll need, I suggest calling reserve so that … Read more

Animating a line drawn between 2 elements without canvas, linking by ID’s

DEMO: CODEPEN Its just plain svg and css keyframe animation. I added separate paths for each of the lines so there are separate animations for all the paths. For timing and delay look at the animation property’s of the different paths. Like animation: Drawpath 1s linear 2s forwards; The first number is the duration of … Read more

get the Type for a object declared dynamic

You need to do this… Type unknown = ((ObjectHandle)tmp).Unwrap().GetType(); By the way, this is a little confusing because if you call Activator.CreateInstance on a type in your current assembly… Activator.CreateInstance(typeof(Foo)) …the object is not wrapped and the original code works fine.

Dynamically add fields to dataclass objects

You could use make_dataclass to create X on the fly: X = make_dataclass(‘X’, [(‘i’, int), (‘s’, str)]) x = X(i=42, s=”text”) asdict(x) # {‘i’: 42, ‘s’: ‘text’} Or as a derived class: @dataclass class X: i: int x = X(i=42) x.__class__ = make_dataclass(‘Y’, fields=[(‘s’, str)], bases=(X,)) x.s=”text” asdict(x) # {‘i’: 42, ‘s’: ‘text’}

How to test whether a value is boxed in C# / .NET?

Try the following public static bool IsBoxed<T>(T value) { return (typeof(T).IsInterface || typeof(T) == typeof(object)) && value != null && value.GetType().IsValueType; } By using a generic we allow the function to take into account both the type of the expression as viewed by the compiler and it’s underlying value. Console.WriteLine(IsBoxed(42)); // False Console.WriteLine(IsBoxed((object)42)); // True … Read more

How to create a dynamic file + link for download in Javascript? [duplicate]

Here’s a solution I’ve created, that allows you to create and download a file in a single click: <html> <body> <button onclick=’download_file(“my_file.txt”, dynamic_text())’>Download</button> <script> function dynamic_text() { return “create your dynamic text here”; } function download_file(name, contents, mime_type) { mime_type = mime_type || “text/plain”; var blob = new Blob([contents], {type: mime_type}); var dlink = document.createElement(‘a’); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)