Thursday, December 30, 2010

Set "Auto" to GridView Colum Width when re-binding data to the GridView

The GridView Colum Width is a headache.

detailView.Columns.OfType<System.Windows.Controls.GridViewColumn>().ToList().ForEach(c => c.Width = c.ActualWidth);
detailView.Columns.OfType<System.Windows.Controls.GridViewColumn>().ToList().ForEach(c => c.Width = Double.NaN);
Double.NaN means auto-size

Wednesday, December 29, 2010

WPF Make a Button invoked by Enter Key, set it as IsDefault=true

In the window, I try to use focus manager to set the button focused to invoke Enter Key, but the focus may lost.

By setting the IsDefault property, problem solved.

public void EnableFinish()
    btnNext.Visibility = Visibility.Hidden;
    btnFinish.Visibility = Visibility.Visible;
    btnFinish.IsDefault = true;

Tuesday, December 28, 2010

Define width of GridViewColumn by parent window

<GridView ColumnHeaderContainerStyle="{StaticResource CustomHeaderStyle}">
      <GridViewColumn Header="Available Roles"
         Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, cestorType={x:Type local:ListViewEx}}, Converter={StaticResource gridViewWidthConverter}, ConverterParameter=0.9}">

Wednesday, December 15, 2010

Timer vs. DispatcherTimer in WPF

Have you ever wondered what is the difference between Timer and DispatcherTimer in WPF / Silverlight? In this post I will try to explain you the little difference. Timer generates recurring events in an application. DispatcherTimer is a timer that is integrated into theDispatcher queue which is processed at a specified interval of time and at a specified priority. Timers are not guaranteed to execute exactly when the time interval occurs, but are guaranteed not to execute before the time interval occurs. This is becauseDispatcherTimer operations are placed on the Dispatcher queue like other operations. When the DispatcherTimer operation executes, it is dependent of the other jobs in the queue and their priorities.

Monday, December 13, 2010

WPF make a window on top of main window

One way is to set the Topmost property, which is not the best way,
another is to set the Owner property,

ProjectWizardDialog pwd = new ProjectWizardDialog();
                pwd.Owner = Window.GetWindow(this);//steveny: Wizard dialog should always be at the toppest