Infolink

 

Search This Blog

Showing posts with label c# examples. Show all posts
Showing posts with label c# examples. Show all posts

Nov 9, 2012

Create an override for a datagrid within a user control(WPF)

The XAML

<UserControl>
 <Grid>
        <toolkit:DataGrid  ItemsSource="{Binding Source={StaticResource DocumentsVS}}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                FontSize="16" Name="_dgDocuments" Style="{StaticResource EklektosDataGridStyle}" . . . >
</UserControl>

OR

<local:MyDataGrid x:Name="dataGrid"/>

In case you want to override the OnCreateAutomationPeer of your dataGrid, you have to subclass the dataGrid -

public class MyDataGrid : DataGrid
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

And in constructor of your UserControl -

public CDocumentChecklistView()
{
    InitializeComponent();
    AutomationPeer a = UIElementAutomationPeer.CreatePeerForElement(dataGrid);
}

Nov 8, 2012

MenuStrip in C#

The MenuStrip class is the foundation of menus functionality in Windows Forms. If you have worked with menus in .NET 1.0 and 2.0, you must be familiar with the MainMenu control. In .NET 3.5 and 4.0, the MainMenu control is replaced with the MenuStrip control.

Creating a MenuStrip

We can create a MenuStrip control using a Forms designer at design-time or using the MenuStrip class in code at run-time or dynamically.

To create a MenuStrip control at design-time, you simply drag and drop a MenuStrip control from Toolbox to a Form in Visual Studio. After you drag and drop a MenuStrip on a Form, the MenuStrip1 is added to the Form and looks like Figure 1. Once a MenuStrip is on the Form, you can add menu items and set its properties and events.
Related Posts Plugin for WordPress, Blogger...