How do I get an animated gif to work in WPF?

I couldn’t get the most popular answer to this question (above by Dario) to work properly. The result was weird, choppy animation with weird artifacts. Best solution I have found so far: https://github.com/XamlAnimatedGif/WpfAnimatedGif You can install it with NuGet PM> Install-Package WpfAnimatedGif and to use it, at a new namespace to the Window where you … Read more

Find all controls in WPF Window by type

This should do the trick: public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject { if (depObj == null) yield return (T)Enumerable.Empty<T>(); for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) { DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i); if (ithChild == null) continue; if (ithChild is T t) yield return t; foreach (T childOfChild in FindVisualChilds<T>(ithChild)) … Read more

MVVM: Tutorial from start to finish?

Your question really seems to be asking 2 questions: Where are some good tutorials on WPF, assuming I have no previous WPF experience? Where are some good tutorials on learning MVVM? Some of these resources may be duplicated in previous answers… Tutorials on WPF A Guided Tour of WPF by Josh Smith I wrote a … Read more

Properties order in Margin

Margin=”1,2,3,4″ Left, Top, Right, Bottom It is also possible to specify just two sizes like this: Margin=”1,2″ Left AND right Top AND bottom Finally you can specify a single size: Margin=”1″ used for all sides The order is the same as in WinForms.

How to bind multiple values to a single WPF TextBlock?

You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat=”{}{0} + {1}”> <Binding Path=”Name” /> <Binding Path=”ID” /> </MultiBinding> </TextBlock.Text> </TextBlock> Giving Name a value of Foo and ID a value of 1, your output in the TextBlock would then be Foo + 1. Note: This … Read more

Handling Dialogs in WPF with MVVM

I suggest forgoing the 1990’s modal dialogs and instead implementing a control as an overlay (canvas+absolute positioning) with visibility tied to a boolean back in the VM. Closer to an ajax type control. This is very useful: <BooleanToVisibilityConverter x:Key=”booltoVis” /> as in: <my:ErrorControl Visibility=”{Binding Path=ThereWasAnError, Mode=TwoWay, Converter={StaticResource booltoVis}, UpdateSourceTrigger=PropertyChanged}”/> Here’s how I have one implemented … Read more

Text vertical alignment in WPF TextBlock

A Textblock itself can’t do vertical alignment The best way to do this that I’ve found is to put the textblock inside a border, so the border does the alignment for you. <Border BorderBrush=”{x:Null}” Height=”50″> <TextBlock TextWrapping=”Wrap” Text=”Some Text” VerticalAlignment=”Center”/> </Border> Note: This is functionally equivalent to using a grid, it just depends how you … Read more

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