Tag Archives: wpf

Filtering elements in a collection

In WPF we have the CollectionView which is the instance type that are bound to Items controls. The CollectionView allows the use of filters, sorting and other features.

To filter the results shown in a items control we can take advantage of the collection view and add a Filter method to it.
Continue reading

Application built on Twitch stream using WPF and C# to copy data to clipboard

I found the “Programming” “game” on Twitch and decided to give it a try, but I needed something interesting and meaningful to develop. So I had this idea of a software to create that can greatly help me on daily basis.

It is an application that allows you to create commands to copy data to clipboard. You can copy plain text, text from files, images from files, files itself.

It uses WPF with MVVM. This is CopyPasterino…
Continue reading

Closing a window in MVVM pattern

The MVVM pattern says that the UI logic should be withing the View. Your ViewModel should not know about the view.

But, imagine the following scenario: you have two buttons on your screen, one to save changes and close and another to cancel and close. But how do you close the window if your view model does not know what is the window and does not know how to handle UI logic?
Continue reading

The MVVM pattern in WPF

In WPF we have the Model-View-ViewModel (MVVM) pattern. This pattern was created to allow you to separate concerns in a way that your business logic is going to be decoupled from your interface.

What happens in this pattern is that your View is going to be purely an user interface. Your ViewModel is going to contain the interface logic, it will be connected to your View through bindings and communicate through notifications. And your Model (for example a database model class) will be able to exchange data directly with your ViewModel.

From MSDN:

Continue reading

WPF TreeView with hierarchical data

TreeView control allows you to create an hierarchical structure. You can tell it to bind elements and also how it should bind the children, grandchildren and so on.

One simple example is as follows:

  <TreeViewItem Header="Character 1">
    <TreeViewItem Header="Character 1's child">
      <TreeViewItem Header="Character 1's child's child"/>
    <TreeViewItem Header="12345"/>
 <TreeViewItem Header="Another char">
    <TreeViewItem Header="Char Bla"/>
    <TreeViewItem Header="Char Foo"/>
    <TreeViewItem Header="98765"/>

Continue reading

WPF: Depencency Properties

Dependency Properties allows you to extend a functionality, from MSDN:

A dependency property provides functionality that extends the functionality of a property as opposed to a property that is backed by a field.

It is used to create bindable properties on objects deriving from DependencyObject, for example in controls. It is used all across WPF.

You can use it as well to create your own bindable properties.

For example:

2015-31-13 05-31-24-043

<local:ExtendedButton DisplayInRed="True"
    Content="I'm red" />
<local:ExtendedButton DisplayInRed="False"
    Content="I'm NOT red" />

<local:ExtendedButton DisplayInRed="{Binding TrueValue}"
    Content="I'm red" />

<Separator />
<local:ExtendedButton2 DisplayInRed="True"
    Content="I'm red" />
<local:ExtendedButton2 DisplayInRed="False"
    Content="I'm NOT red" />

<!--Error, cannot bind-->
<!--<local:ExtendedButton2 DisplayInRed="{Binding TrueValue}"
    Content="I'm red" />-->

Continue reading

Nuget Package: ValueInjecter

ValueInjecter is a nuget package that allows you to inject values from one object to another.

ValueInjecter lets you define your own convention-based matching algorithms (ValueInjections) in order to match up (inject) source values to destination values. It is used for mapping Dto to Entity and back also for mapping IDataReader to objects, windows forms to object, basically anything. Also has support for flattening and unflattening.

One good use for ValueInjecter is when you are working with models and viewmodels. With it you can build models from viewmodels and viewmodels from models.
Continue reading