Pages

Saturday, October 20, 2012

C# Writing Custom Configuration Settings Section

Almost every C# application has its own Configuration Settings file also known as App.Config. If you look on your App.Config file you probably will see a list of key value pairs:
<add key="key0" value="value0" />
<add key="key1" value="value1" /> 
<add key="key2" value="value2" />
... 
But what if you need some more complex configurations? Something like this:
<MySection>
    <MySettings MyKey="John" MyValue1="Developer" MyValue2="Expert"/>
    <MySettings MyKey="Tomas" MyValue1="Developer" MyValue2="Junior"/>    
    <MySettings MyKey="Robert" MyValue1="Developer" MyValue2="Senior"/>
    <MySettings MyKey="Kurt" MyValue1="IT" MyValue2="Expert"/>
    <MySettings MyKey="Anna" MyValue1="HR" MyValue2="Senior"/>    
</MySection>
Today I'll show how to build this kind of Custom Configuration Settings in C#.

Saturday, October 13, 2012

Speech Synthesizer in WPF

I recently came across with some very interesting feature in C# - Speech Synthesizer! Speech Synthesizer is Microsoft API which allows to build speech enabled applications. Just one row of code and your WPF application will spell any textual data!
All you need is just add a reference to System.Speech.Synthesis and a couple rows of code. I built a simple application just to show how to use Speech Synthesizer in WPF.
Speech Synthesizer in WPF
Here is the XAML code of the GUI:
<TextBox Grid.Column="0" Grid.Row="0"
         HorizontalAlignment="Left"
         TextWrapping="Wrap"
         AcceptsReturn="True"
         VerticalScrollBarVisibility="Visible"
         FontSize="14"
         Height="100"
         Width="270"
         Name="TextBox_Read">Talk to me!</TextBox>

<Button Grid.Column="1" Grid.Row="1"                
        Name="Button_Say"
        Content="Say" Click="Button_Say_Click"></Button>

<Button Grid.Column="1" Grid.Row="2"                
        Name="Button_Who"
        Content="Who's talking?" Click="Button_Who_Click"></Button>

<Slider Grid.Column="0" Grid.Row="1" 
        Name="Slider_Volume"
        Value="50" Minimum="0" Maximum="100"
        TickFrequency="5" ValueChanged="VolumeChanged"
        ToolTip="Volume"/>

<Slider Grid.Column="0" Grid.Row="2" 
        Name="Slider_Rate"
        Value="0" Minimum="-5" Maximum="7" 
        TickFrequency="1" ValueChanged="RateChanged"
        ToolTip="Speech Rate"/>