Pages

Sunday, March 25, 2012

Accessing App.Config Properties From XAML



Problem:

How to access user settings stored in app.config file from XAML?

Accessing app.config from XAML

Solution:

First we need to add reference to Properties in our XAML file.
xmlns:p="clr-namespace:MyExample.Properties"
And this is how we use it:
<TextBox Name="serverNameTextBox" 
         Grid.Column="1" Grid.Row="0"
         Text="{Binding Source={x:Static p:Settings.Default}, 
                                Path=ServerName, Mode=OneWay}">
</TextBox>
Hope it will save your time.

Wednesday, March 14, 2012

WPF DateTimePicker In DataGrid


Problem:

Need to integrate DateTimePicker control into datagrid cell.
Datagrid with DateTimePicker

Solution:

For some business applications regular WPF DatePicker is not enough, sometimes you need also time and seconds.
I was quite surprised when figured out that .NET Framework 4.0 does not have such control as DateTimePicker.
Well, fortunately there is such a thing called Extended WPF Toolkit.
All you need is download it and to add reference to WPFToolkit.Extended.dll in your WPF project.
Here is how you use DateTimePicker with DataGrid:

Tuesday, March 13, 2012

WPF Datagrid Edit Row Toggle Button



Problem:

I have a WPF datagrid with some data, some of the fields are configurable.
I don`t want user to change data in datagrid unless he enters into Edit Mode for specific row.
User can edit only one row at the same time.


Solution:

DataGrid, edit mode locked
Edit Mode locked for all rows


DataGrid, edit mode unlocked
Edit Mode unlocked for second row