WPF Quick Reminders

Windows Forms Integration

Dim myControl1 = New WpfControlLibrary.CustomControl1
 myControl1.Content = "Hello World"
Me.ElementHost1.Child = myControl1

Docking

You may want HorizontalAlignment or VerticalAlignment = “Stretch”

DataBinding

Imports System.Data.Entity

private AccountTypeContext _context = new AccountTypeContext();
private CollectionViewSource myCollectionViewSource;
//Next in Loaded. If in user control then:
// Do not load your data at design time.
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
{ }
 myCollectionViewSource = (CollectionViewSource)this.Resources["accountTypeViewSource"];
_context.AccountTypes.Load();
myCollectionViewSource.Source = _context.AccountTypes.Local;

DataBinding – BindingNavigator Functions

        private void MoveFirstButton_Click(object sender, RoutedEventArgs e)
        {
            myCollectionViewSource.View.MoveCurrentToFirst();
        }
        private void MovePreviousButton_Click(object sender, RoutedEventArgs e)
        {
            myCollectionViewSource.View.MoveCurrentToPrevious();
        }
        private void MoveNextButton_Click(object sender, RoutedEventArgs e)
        {
            myCollectionViewSource.View.MoveCurrentToNext();
        }
        private void MoveLastButton_Click(object sender, RoutedEventArgs e)
        {
            myCollectionViewSource.View.MoveCurrentToLast();
        }
//


It may be necessary to use
myDataGrid.ScrollIntoView(myDataGrid.SelectedItem);

 

DataBinding – Filter

With acknowledgment to:

http://www.chateau-logic.com/content/wpf-entity-framework-listbox-datagrid-filtering-using-collectionviewsource-collectionview

and

http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(SYSTEM.WINDOWS.DATA.COLLECTIONVIEWSOURCE.FILTER);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true

In _Loaded

       myCollectionViewSource.Filter += new FilterEventHandler(FilterTextBoxLike);
In Code - assuming you have a text box called FilterTextBox
        #region Filter
        bool FilterClearing;
        private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)        {
            try             {
                if (FilterClearing == false)                    {
                        RefreshList();                    }
            }
            catch (Exception ex)            {
                MessageBox.Show(ex.Message);    
            }
        }

        private void RefreshList()
        {
            myCollectionViewSource.View.Refresh();
        }

        private void FilterTextBoxLike(object sender, FilterEventArgs e)
        {
            AccountType at = e.Item as AccountType;

            if (at.AccountType1.ToLower().Contains(FilterTextBox.Text.ToLower()))
            {
                e.Accepted = true;
            }
            else
            {
                e.Accepted = false;
            }
        }

        private void ClearFilterButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
		FilterClearing = true;
               FilterTextBox.Text = "";
		RefreshList();
            }
            catch (Exception ex)
            {
		MessageBox.Show(ex.Message);                
            }
            FilterClearing = false;
        }

        #endregion

.

Data Grid – Styles

 

DatePicker as UK style date

Two actions seem to be required

Imports System.Globalization
Imports System.Threading

Namespace My

Partial Friend Class MyApplication

Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
Dim ci = New CultureInfo(Thread.CurrentThread.CurrentCulture.Name)
ci.DateTimeFormat.ShortDatePattern = “dd-MMM-yyyy”
Thread.CurrentThread.CurrentCulture = ci
End Sub

End Class

End Namespace

<DatePicker Name=”DateReportedTextBox” Text=”{Binding Path=DateReported, StringFormat={}{0:dd-MMM-yyyy}}” />


End

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: