Dailycode.info

Short solution for short problems

Devexpress 10: WPF GridControl - Show bound column in date time format

I took me a while to find, but at the end I got it.

The problem was when I start using Devexpress 10 (we’re in the process of buying the latest version, but not there yet) WPF GridControl, the datatime column only showed date.

Not a big deal, or so I thought. The first solution I found was to use the TextEditSettings. But that was in a differtent namespace. Therefore I had to add an assembly that I couldn’t find.

Eg. xmlns:dxe="clr-namespace:DevExpress.Wpf.Editors.Settings;assembly=DevExpress.Wpf.Editors.v9.1"

 

So I looked around but couldn’t find it. Too bad I thought and start looking further into the Template columns, but everywhere the binding failed. This because I work with DataSource of the grid, not the DataContext.

 Now at the end I found that I already had the assembly and it wasn’t DevExpress.Wpf. Just by adding this namespace in my xaml I could use the TextEditSettings:

xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"

 

So now I just use this piece of code to show my desired format of the date:

<dxg:GridColumn Name="createdtest" Header="Erzellt" FieldName="Created">

<dxg:GridColumn.EditSettings>

             <dxe:TextEditSettings DisplayFormat="dd/MM/yyyy HH:MM" />

</dxg:GridColumn.EditSettings>

</dxg:GridColumn>

 

That’s al there is about it!

This is all the code for the GridControl:

<UserControl xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 

             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"

 

<dxg:GridControl DataSource="{Binding Path=SearchList}"  AutoPopulateColumns="False">

            <dxg:GridControl.Columns>

                <dxg:GridColumn Name="gridColumn1" Header="Kunde Nr." FieldName="Key2" ReadOnly="True"/>

                <dxg:GridColumn Name="gridColumn2" Header="Kunde Name" FieldName="Key3" ReadOnly="True" Width="500"/>

                <dxg:GridColumn Name="gridColumn3" Header="Mandant" FieldName="Key4" ReadOnly="True"/>

                <dxg:GridColumn Name="gridColumn4" Header="Kunde BW" FieldName="Key5" ReadOnly="True"/>

                <dxg:GridColumn Name="createdtest" Header="Erzellt" FieldName="Created">

                    <dxg:GridColumn.EditSettings>

                        <dxe:TextEditSettings DisplayFormat="dd/MM/yyyy HH:MM" />

                    </dxg:GridColumn.EditSettings>

                </dxg:GridColumn>

            </dxg:GridControl.Columns>

               

        </dxg:GridControl>

 

 

 

 


WPF - MVVM: Easy wait cursor implementation

Found a very good solution on StackOverflow.

Comes down to implementing a small class, better put it somewhere in your WPF framework or Shared library.

Call it like this:

UIHelper.SetBusyState();

The cursor will return to normal when the  application stops working.

 

Code:
using System;
using System.Windows.Input;
using System.Windows.Threading;

namespace Global.Wpf
{
    public static class UIHelper
    {
        /// <summary>
        ///   A value indicating whether the UI is currently busy
        /// </summary>
        private static bool IsBusy;

        /// <summary>
        /// Sets the busystate as busy.
        /// </summary>
        public static void SetBusyState()
        {
            SetBusyState(true);
        }

        /// <summary>
        /// Sets the busystate to busy or not busy.
        /// </summary>
        /// <param name="busy">if set to <c>true</c> the application is now busy.</param>
        private static void SetBusyState(bool busy)
        {
            if (busy != IsBusy)
            {
                IsBusy = busy;
                Mouse.OverrideCursor = busy ? Cursors.Wait : null;

                if (IsBusy)
                {
                    new DispatcherTimer(TimeSpan.FromSeconds(0), DispatcherPriority.ApplicationIdle, dispatcherTimer_Tick, System.Windows.Application.Current.Dispatcher);
                }
            }
        }

        /// <summary>
        /// Handles the Tick event of the dispatcherTimer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private static void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            var dispatcherTimer = sender as DispatcherTimer;
            if (dispatcherTimer != null)
            {
                SetBusyState(false);
                dispatcherTimer.Stop();
            }
        }
    }
}