Search This Blog

Tuesday, August 22, 2017

Display XAML window in the second display WPF

WPF > Windows > Forms > Screen

AllScreens gets an array of all displays on the system.

Example

Display window in the second display WPF

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   var screen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).First();
   var area = screen.WorkingArea;
   Left = area.Left;
   Top = area.Top;
   Width = area.Width;
   Height = area.Height;
}

Wednesday, July 26, 2017

GridViewColumnHeader WPF Example

WPF > Controls  > ContentControl > GridViewColumnHeader

GridViewColumnHeader object is a button control that is derived from ButtonBase. 
Column headers in a GridView view mode are GridViewColumnHeader objects.
Example

<Window x:Class="GridViewColumnHeader.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:GridViewColumnHeader"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListView>
            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumnHeader>Name
                            <GridViewColumnHeader.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Ascending" />
                                    <MenuItem Header="Descending" />
                                </ContextMenu>
                            </GridViewColumnHeader.ContextMenu>
                        </GridViewColumnHeader>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>



Wednesday, July 12, 2017

Get Vertical ScrollBar Width WPF

WPF > Windows > SystemParameters > VerticalScrollBarWidth


This value indicates the width (in pixels) of a vertical scroll bar.

SystemParameters.VerticalScrollBarWidth

WPF SystemParameters Class

WPF > Windows > SystemParameters


Thursday, May 4, 2017

Bind Width to another Width control WPF

WPF > Binding > Width

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition 
Width="{Binding ElementName=controlName, Path=ActualWidth}"/>
  </Grid.ColumnDefinitions>

Monday, March 13, 2017

ScrollToTop DataGrid WPF

WPF> DataGrid > Scroll To Top


var border = VisualTreeHelper.GetChild(myDataGrid, 0) as Decorator;
if (border != null && border.Child !=null)
{
  var scrollViewer = border.Child as ScrollViewer;
  if (scrollViewer != null)
  {
    scrollViewer.ScrollToTop();
  }

}

Thursday, March 2, 2017

FrameworkElementFactory focus on load element

WPF > FrameworkElementFactory > AddHandler


FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
textBox.AddHandler(TextBox.LoadedEvent, new RoutedEventHandler(OnTextBoxLoaded));

private void OnTextBoxLoaded(object sender, RoutedEventArgs e)
{
       TextBox textBox = sender as TextBox;
       if (textBox != null)
       {
              textBox.Focus();
       }
}

Tuesday, February 21, 2017

Disable row selection datagrid WPF


How to disable row selection in datagrid WPF?

Answer:

myDataGrid.IsHitTestVisible = false;

Thursday, January 26, 2017

Find TextBox control ComboBox WPF

WPF > Controls > ItemsControl > ComboBox

Use FindName to find an element that has the provided identifier name.


PART_EditableTextBox
TextBox
Contains the text of the ComboBox

Example

var textBox = comboBox.Template.FindName("PART_EditableTextBox", comboBox) as TextBox;