How can I wrap text in a label using WPF?

The Label control doesn’t directly support text wrapping in WPF. You should use a TextBlock instead. (Of course, you can place the TextBlock inside of a Label control, if you wish.) Sample code: <TextBlock TextWrapping=”WrapWithOverflow”> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec adipiscing nulla quis libero egestas lobortis. Duis blandit imperdiet ornare. Nulla … Read more

How can I find WPF controls by name or type?

I combined the template format used by John Myczek and Tri Q’s algorithm above to create a findChild Algorithm that can be used on any parent. Keep in mind that recursively searching a tree downwards could be a lengthy process. I’ve only spot-checked this on a WPF application, please comment on any errors you might … Read more

Watermark / hint / placeholder text in TextBox?

You can create a watermark that can be added to any TextBox with an Attached Property. Here is the source for the Attached Property: using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Documents; /// <summary> /// Class that provides the Watermark attached property /// </summary> public static class WatermarkService { … Read more

Open directory dialog

You can use the built-in FolderBrowserDialog class for this. Don’t mind that it’s in the System.Windows.Forms namespace. using (var dialog = new System.Windows.Forms.FolderBrowserDialog()) { System.Windows.Forms.DialogResult result = dialog.ShowDialog(); } If you want the window to be modal over some WPF window, see the question How to use a FolderBrowserDialog from a WPF application. EDIT: If … Read more

Difference between Visibility.Collapsed and Visibility.Hidden

The difference is that Visibility.Hidden hides the control, but reserves the space it occupies in the layout. So it renders whitespace instead of the control. Visibilty.Collapsed does not render the control and does not reserve the whitespace. The space the control would take is ‘collapsed’, hence the name. The exact text from the MSDN: Collapsed: … Read more

ListBox vs. ListView – how to choose for data binding

A ListView is a specialized ListBox (that is, it inherits from ListBox). It allows you to specify different views rather than a straight list. You can either roll your own view, or use GridView (think explorer-like “details view”). It’s basically the multi-column listbox, the cousin of windows form’s listview. If you don’t need the additional … Read more

How to get controls in WPF to fill available space?

There are also some properties you can set to force a control to fill its available space when it would otherwise not do so. For example, you can say: HorizontalContentAlignment=”Stretch” … to force the contents of a control to stretch horizontally. Or you can say: HorizontalAlignment=”Stretch” … to force the control itself to stretch horizontally … Read more

Setting WPF image source in code

After having the same problem as you and doing some reading, I discovered the solution – Pack URIs. I did the following in code: Image finalImage = new Image(); finalImage.Width = 80; … BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.UriSource = new Uri(“pack://application:,,,/AssemblyName;component/Resources/logo.png”); logo.EndInit(); … finalImage.Source = logo; Or shorter, by using another BitmapImage constructor: … Read more

How does Windows 8 Runtime (WinRT / Windows Store apps / Windows 10 Universal App) compare to Silverlight and WPF? [closed]

At the lowest level, WinRT is an object model defined on ABI level. It uses COM as a base (so every WinRT object implements IUnknown and does refcounting), and builds from there. It does add quite a lot of new concepts in comparison to COM of old, most of which come directly from .NET – … Read more

WPF global exception handler [duplicate]

You can trap unhandled exceptions at different levels: AppDomain.CurrentDomain.UnhandledException From all threads in the AppDomain. Dispatcher.UnhandledException From a single specific UI dispatcher thread. Application.Current.DispatcherUnhandledException From the main UI dispatcher thread in your WPF application. TaskScheduler.UnobservedTaskException from within each AppDomain that uses a task scheduler for asynchronous operations. You should consider what level you need to … Read more

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