Tuesday, May 21, 2013

Quick challenge #2: how to truncate a string in C# and keep word boundaries (do not split a word in two)

[Q] How to truncate a string in C# with more than 10 characters and keep word boundaries (do not split a word in two)?

[Examples] "Good morning test." -> "Good morni..." (wrong), "Good morning..." (correct)

Thursday, May 16, 2013

How to make a consistent bind in WPF.

Hello everyone, to make your first bind can be a very traumatizing experience and even for someone with a little more experience a simple mistake can drive you crazy. So in this post we are showing some tips and good practice to make a consistent binding. First of all we recommend the Josh Smith post, that in fact is one of our references for this little post.

Friday, May 10, 2013

Wednesday, May 8, 2013

How to Bind to a DataGrid when its columns are not known at compile time (ItemsSource is bidimensional)

Making a Bind in a WPF DataGrid is not the the most difficult task. In fact, there are dozens of posts explaining how to do it (http://wpftutorial.net/DataGrid.html, http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples). However, they all have one detail in common: they assume that the columns of the DataGrid are known at compile time, ie., each column is a reference to a property of class that represents a row in the DataGrid.

An example: the class Customer has the properties Id, Name and Age. The DataGrid displays a list of customers. Therefore, it is necessary to create a column for each property. To do so, simply create in xaml, three instances of the class DataGridTextColumn and make a bind to each of the 3 properties, like following code:

How insert a button in a datagrid row header

Sometimes we need to do some strange things, like adding a button in a row header of a datagrid. In my case I am looking for something like a treeview datagrid, and adding a button in a datagrid row header is one of the things we need to do (here the part 1 of my saga, where we show how to collapse lines in a datagrid). So, in this post we are going to show some tricks to let you bind your View Model Property with your button properties.

Friday, April 26, 2013

Checkbox on datagrid with single click.

It is quite common to use checkbox in a datagrid. To make our lives easier the WPF DataGrid has a class called DataGridCheckBoxColumn to easily add a column in your datagrid a checkbox column format. However, this class has a drawback behavior that makes the user have to click twice on the checkbox inside the datagrid to select it. Unfortunately there is no property (up to the moment of publishing this post) that makes this boring behavior abolished.
But all is not lost, you'll see in this minipost with few lines of code how you can customize your datagrid to create a column that contains checkbox to be selected with a single click!

Friday, April 19, 2013

Custom WPF Progress Bars - Part I

One of the biggest advantages of Windows Presentation Foundation Technology of Microsoft is the freedom that the developer must create or modify existing components. This is possible because all traditional components (TextBox, CheckBox, ComboBox, Menu, ProgressBar, TreeView, etc.) are mounted literally like lego bricks, the From the most basic components. These basic components are implemented the System.Windows.Controls assembly and, among the main are: Grid, StackPanel, DockPanel, Border, Canvas and Image. The use of these elements together with elements present in other assemblies that help developer to implement geometric designs (Rectangle, Circle) and basic interactions (MouseOver, Click, etc) allow you to create, basically component you want.
The ProgressBar component of WPF is no different. It is formed by three graphic elements, whose names are well defined:
·         PART_Indicator: component part which indicates the progress indeed.
·         PART_Track: indicates the trail or path that is traversed by indicator (PART_Indicator).
·         PART_GlowRect: this is only a component to help with visual effects.
The purpose of this post is to show how these three elements can be created and attached to existing code ProgressBar component to generate a progress bar that looks arbitrary.

Flash Tip: Getting the whole text of a RichTextBox instance

This is a flash-like post. I have seen too many people on my work ask: how do I get the whole text of a RichTextBox?

TreeView DataGrid with collapsible lines.

Datagrid is the easiest way to display data in tables, but sometimes a simple datagrid is not enough. Sometimes we need to group certain types of data with properties in common, something like a treeview. Imagine you have a system where the user register multiple employees, and some of these employees are managers and these managers have subordinates. The user of the system may require the datagrid view only users who are not managers, or vice versa. For this you need to create something like a TreevireeDataGrid, or a datagrid in three or more dimensions (a tradicional datagrid has only two dimensions, row and column).
In order to create this desired TreeviewDatagrid we divide this task into three parts. In this first post we will show you how to hide rows in a DataGrid, you'll see that this is a fundamental part in the process.
In the second post will show how to edit the header of the datagrid to add pictures to it (like a button) to collapse or show the items that belong to him.No terceiro post vamos tratar da lógica de fazer um TreeviewDatagrid e juntar o conhecimento de todos os posts anteriores.

Friday, April 12, 2013

Update de Segurança KB 2823324 do Windows 7 32-bit

Se você tem um PC com Windows 7 32 bits recém atualizado, provavelmente você NÃO está vendo esse post com ele. Isso porque a Microsoft  lançou uma fantástica atualização, de nome KB 2823324, que provavelmente matou com um tiro na cabeça e a sangue frio o seu amado PC!! Mas não se preocupe, a Microsoft acaba de lançar um post em sua página pedindo sinceras desculpas (obrigado) e mostrando uma gambiarra solução para o problema. Que consistem, basicamente, em restaurar o instalação do Windows e remover na marra a atualização demoníaca com problema KB 2823324 !!

A Microsoft possui uma página específica para este problema, você pode acessar o link aqui.