Tag Archives: wpf

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:

mvvm
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:

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

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