Skip to main content

WPF – Enum Binding in a ComboBox – The Classic Way

Enum binding to combobox

Hello Devz, I had to write this post about how to do an Enum binding to a ComboBox, because everytime I need it, I’m surprised there is no “out-of-the-box” solution provided in WPF or Xamarin.Forms. <Window x:Class=”EnumBinding.MainWindow” xmlns=”” xmlns:x=”” xmlns:d=”″ xmlns:mc=”″ xmlns:local=”clr-namespace:EnumBinding” xmlns:sys=”clr-namespace:System;assembly=mscorlib” mc:Ignorable=”d” Title=”MainWindow” Height=”350″ Width=”525″> <Window.Resources> <ObjectDataProvider x:Key=”dataFromEnum” MethodName=”GetValues” ObjectType=”{x:Type sys:Enum}”> <ObjectDataProvider.MethodParameters> <x:Type TypeName=”local:StatusEnum”/> </ObjectDataProvider.MethodParameters> […]

WPF – PasswordBox Helper


Because security matters, you will need at one point to use a PasswordBox in your WPF application (you know, the textBox hiding the password with stars). But Microsoft didn’t make this control bindable for security reasons (in memory access). So if you’re using MVVM, it will be a bit tricky. Different solutions exist, but really […]

WPF – Animated text

Sometimes it can be useful to have an animated text even in WPF. Typically a “Loading…”, where the 3 dots are moving one by one. Here is a simple way to do an animation with text: <StackPanel Orientation=”Horizontal” Margin=”20″> <Button Content=”Start” Height=”20″ Command=”{Binding StartCommand}” VerticalAlignment=”Top” Margin=”5″ /> <Button Content=”Stop” Height=”20″ Command=”{Binding StopCommand}” VerticalAlignment=”Top” Margin=”5″ /> […]

WPF – Nullable binding

Hello Devz, Imagine you have a TextBox binded to a nullable integer and you put a value in it. Now let’s say you delete this value. You expect to have your value to be null. To be able to do that, you need to update the properties of you binding like this: <TextBox Text=”{Binding Value, […]

WPF – MessageBox on top of the other Views

Hello devz, It happens sometimes with WPF that a popup or a MessageBox is hidden and can block the whole application. To avoid this, just do the following: var msgBoxResult = MessageBox.Show(Application.Current.MainWindow, “Are you sure?”, “Delete item”, MessageBoxButton.YesNo, MessageBoxImage.Question); The Application.Current.MainWindow is the solution… But please pay attention that this parameter can be different! Indeed it’s […]

C# – Coma and Dot decimal separator

Hi peeps, You probably know the common issue with the decimal seprator. Depending on the country, the keyboard or what your client wants (which can be variable…), the separator will be a coma or a dot (or even something else…). In my case, the Culture is “en-US“, on a Belgian keyboard where the decimal separator […]

WPF – Change color of a row in a DataGrid depending on the value with DataTrigger

Hi folks, Today we will see how to change the color or a row depending on the value of the content. To do that, create a simple View: <Window x:Class=”DataTrigger_Test.MainWindow” xmlns=”” xmlns:x=”” xmlns:d=”″ xmlns:mc=”″ mc:Ignorable=”d” Title=”MainWindow” Height=”350″ Width=”525″> <Grid> <DataGrid Margin=”10″ ItemsSource=”{Binding Users}” AutoGenerateColumns=”False” ColumnWidth=”*” HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch” HorizontalContentAlignment=”Stretch” EnableRowVirtualization=”false” EnableColumnVirtualization=”false” CanUserAddRows=”False” CanUserReorderColumns=”False” CanUserResizeColumns=”True”> <DataGrid.CellStyle> <Style […]