Start Microsoft Visual Studio. wpf5concat File New Project WPF Application, Name= wpf5concat OK. The Solution Explorer displays: Solution wpf5concat, wpf5concat, Properties, References, App.xaml, MainWindow.xaml. The MainWindow is automatically covered by a Grid element. Click an interior of the MainWindow. This selects the Grid, and surrounds it by a rim. Click three times the left rim to split the Grid into four rows. From the Toolbox drag four StackPanel controls, and drop each of them onto separate Grid s row. In Properties pane, set their names to: spodd, spamick, spselmany, spaa. For every StackPannel, in the Properties pane, set: Orientation= Horizontal, and adjust their dimensions to those of the Grid s rows. From the Toolbox drag and drop some controls: Seven TextBlock controls: txbkodd, txbkeven, txbkoddeven, txbkunidesce, txbkselconc, txbkselmany, txbktmpl, Ten TextBox controls: txbodd, txbeven, txboddeven, txbdesce, txbam, txbjs, txbselmany, txbtmpl, txbpresent, txbaa, Three ListBox controls: lbx1, lbx2, lbx3. Position the controls making use of the properties VerticalAlignment= Stretch or Top, and Margin= e.g. 5,-42, 0, 0. In the Properties pane set the background colors, the Bold (for TextBox controls) and the Text properties: {1,3,5, {2,4,6, clk me, 2clk me, Adam Mickiewicz, Juliusz Slowacki, ^Aa{2c{3de.
See the screenshot. In the Properties pane, in the Events tab, for the controls marked by the Azure background color subscribe for events MouseDown or MouseDoubleClick. To the file MainWindow.xaml.cs add the following code, which includes event handlers. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Text.RegularExpressions; //Regex namespace wpf5concat { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() {InitializeComponent(); //ctor.
private void txboddeven_mousedoubleclick(object sender, MouseButtonEventArgs e) {if(txboddeven.text!="2clk me") {txboddeven.text="2clk me"; txbdesce.text= ""; {Regex rex= new Regex("{,"); //x=>"" ==MatchEvaluator: char[] todd= rex.replace(txbodd. Text,x=>"").ToCharArray(); char[] teven=rex.replace(txbeven.text,x=>"").tochararray(); IEnumerable<char> enoddeven= todd.concat(teven); txboddeven.text= enoddeven.aggregate("{",(x,y)=>x+=y+", ").TrimEnd(' ',',')+""; IEnumerable<int> endesce= enoddeven.select(x=>(int)x).orderbydescending<int,int>(x=>(int)x); txbdesce.text= //seed, accumulate function: endesce.aggregate("{",(x,y)=>x+=y+", ").TrimEnd(' ',',')+""; //, private void lbx1_mousedown(object sender, MouseButtonEventArgs e) {if(lbx1.itemssource!=null) {lbx1.itemssource= null; lbx1.items.add("clk me"); lbx2.itemssource= null; lbx3.itemssource= null; {string[] tam= txbam.text.split( string[] tjs= txbjs.text.split( IEnumerable<string> en= tam.concat(tjs); lbx1.items.clear(); lbx1.itemssource= en.orderby(x=>x); lbx2.itemssource= en.orderbydescending(x=>x[x.length-1]); lbx3.itemssource= en.orderbydescending(x=>x.reverse().aggregate("",(z,y)=>z+=y)); //. private void lbx1_gotfocus(object sender,routedeventargs e) {lbx1.itemssource= null; lbx1.items.clear(); lbx1.items.add("clk me"); lbx2.itemssource= null; lbx3.itemssource= null; private void txbselmany_mousedoubleclick(object sender, MouseButtonEventArgs e) {if(txbselmany.text!="2clk me") {txbselmany.text="2clk me"; {IEnumerable<string> enam= txbam.text.split( IEnumerable<string> enjs= txbjs.text.split( IEnumerable<char> enchar= enam.concat(enjs).selectmany(x=>x); txbselmany.text= enchar.orderby(x=>x).orderby(x=>x<97?x:x-'a'+'a').aggregate("",(x,y)=>x+=y); //.
private void txbpresent_mousedoubleclick(object sender,mousebuttoneventargs e) {if(txbpresent.text!="2clk me") txbpresent.text= "2clk me"; {Regex rex= new Regex(txbTmpl.Text); if(txbselmany.text==null rex.ismatch(txbselmany.text)) txbpresent.text= "present"; txbpresent.text= "absent"; //. private void txbselmany_textchanged(object sender, TextChangedEventArgs e) {if(txbpresent!=null) txbpresent.text="2clk me"; private void txbtmpl_textchanged(object sender, TextChangedEventArgs e) {if(txbpresent!=null) txbpresent.text="2clk me"; private void txbaa_mousedoubleclick(object sender, MouseButtonEventArgs e) {if(txbaa.text!="2clk me") txbaa.text= "2clk me"; {IEnumerable<string> enam= txbam.text.split( IEnumerable<string> enjs= txbjs.text.split( txbaa.text= enam.concat(enjs).select(x=>x.substring(0,3).tochararray()).select(x=>x.select( y=>x[0].tostring().tolower()+y.tostring().toupper()+' ').ToArray()).Select(x=>x.Aggregate("",(z,y)=>z+=y)).Select(x=>x.PadRight(x.Length+9,' ')).Aggregate("",(x,y)=>x+=y); //. //class. After Ctrl + F5:
A double-click on the right-top TextBox control causes concatenation of the odd and even numbers, ordering them and displaying them as characters and as Unicode values. A click on the first of the three ListBox controls causes concatenation of the Adam Mickiewicz and Juliusz Slowacki strings, In the ListBox control lbx1, the four strings are ordered in an ascending (default) manner. In the lbx2 control they are ordered in a descending manner, with respect to the last characters. In the lbx3 control they are ordered in a descending manner, with respect to the reversed order of the characters within each of the four strings. A click on the TextBox control following the SelMany= control displays the characters from the Adam Mickiewicz and Juliusz Slowacki strings, whereby the characters are ordered in an ascending manner. The string ^Aa{2c{3de in the TextBox control is a template used by a Regex object rex. The function IsMatch checks whether the previous character-string contains the template. If it does, the TextBox control below the template displays present. If it does not the displayed text is absent. A click on the very bottom TextBox control displays four groups of characters. Each of these groups consists of three tuples of characters. The upper case characters are the three first characters from the strings Adam, Mickiewicz, Juliusz, Slowacki. Every upper case character is preceded by the first character of these strings, made lower case. The idea here was to demonstrate a bit more sophisticated use of the standard query operators. After clicking or double-clicking the above mentioned controls: The toggle behaviors are implemented for every click (MouseDown) or double click (MouseDoubleClick) events.
The layout of the MainWindow is coded in the MainWindow.xaml file: <Window x:class="wpf5concat.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="80*" /> <RowDefinition Height="110*" /> <RowDefinition Height="60*" /> <RowDefinition Height="60*" /> </Grid.RowDefinitions> <StackPanel Name="spOdd" Height="80" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503" Orientation="Horizontal" Background="#FFFFF0F0"> <TextBlock Name="txbkOdd" Height="23" Text="Odd=" Background="White" Margin="5,-42,0,0" /> <TextBox Name="txbOdd" Height="23" Width="80" Margin="5,-45,0,0" Text="{{1,3,5" FontWeight="Bold" /> <TextBlock Name="txbkEven" Background="White" Height="23" Text="Even=" Margin="10,-42,0,0" /> <TextBox Name="txbEven" FontWeight="Bold" Height="23" Text="{{2,4,6" Width="80" Margin="5,-45,0,0" IsEnabled="True" /> <TextBlock Name="txbkOddEven" Background="White" Height="23" Text="OddEven=" Margin="20,-42,0,0" /> <TextBox Name="txbOddEven" FontWeight="Bold" Height="23" Text="2clk me" Width="170" Margin="5,-45,0,0" IsReadOnly="True" AcceptsReturn="False" IsEnabled="True" AcceptsTab="False" MouseDoubleClick="txbOddEven_MouseDoubleClick" Background="Azure" /> <TextBlock Name="txbkUniDesce" Height="23" Width="65" Margin="- 400,13,0,0" Background="White" Text="UniDesce=" /> <TextBox Name="txbDesce" AcceptsReturn="False" AcceptsTab="False" FontWeight="Bold" Height="23" IsEnabled="True" IsReadOnly="True" Text="" Width="170" Margin="-170,10,0,0" /> <StackPanel Name="spAMick" Grid.Row="1" Height="111" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503" Orientation="Horizontal" Background="#FFEBEBFF"> <TextBox Height="23" Name="txbAM" Width="110" Margin="1,5,0,0" Text="Adam Mickiewicz" FontWeight="Bold" VerticalAlignment="Top" /> <TextBox Height="23" Name="txbJS" Width="105" Margin="4,5,0,0" Text="Juliusz Slowacki" FontWeight="Bold" VerticalAlignment="Top" /> <TextBlock Height="23" Name="txbkSelConc" Text="SelConc=" Margin="5,7,0,0" VerticalAlignment="Top" /> <ListBox Height="95" Name="lbx1" Width="73" Margin="2,4,0,0" Background="Azure" MouseDown="lbx1_MouseDown" VerticalAlignment="Top" FontWeight="Bold" IsEnabled="True" Focusable="True" IsHitTestVisible="True" SelectionMode="Single" IsManipulationEnabled="False" IsTabStop="False" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" OverridesDefaultStyle="False" GotFocus="lbx1_GotFocus"> <ListBoxItem Content="clk me" /> </ListBox> <ListBox Height="95" Name="lbx2" Width="73" Margin="3,5,0,0" VerticalAlignment="Top" FontWeight="Bold" /> <ListBox Height="95" Name="lbx3" Width="73" Margin="3,5,0,0" VerticalAlignment="Top" FontWeight="Bold" />
<StackPanel Name="spSelMany" Grid.Row="2" Height="60" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503" Orientation="Horizontal" Background="#FFFFF0F0"> <TextBlock Height="23" Name="txbkSelMany" Text="SelMany=" Background="White" Margin="5,0,0,0" /> <TextBox Height="23" Name="txbSelMany" Width="204" Background="Azure" FontWeight="Bold" MouseDoubleClick="txbSelMany_MouseDoubleClick" TextChanged="txbSelMany_TextChanged" Text="2clk me" /> <TextBlock Height="23" Name="txbkTmpl" Text="reg.expr.Tmpl=" Margin="5,0,0,0" Background="White" /> <TextBox Height="23" Name="txbTmpl" Width="155" Background="White" FontWeight="Bold" VerticalAlignment="Top" Margin="0,10,0,0" Text="^Aa{2c{3de" TextChanged="txbTmpl_TextChanged" /> <TextBox Height="23" Name="txbPresent" Width="60" Text="2clk me" FontWeight="Bold" VerticalAlignment="Center" Margin="-180,27,0,0" Background="Azure" MouseDoubleClick="txbPresent_MouseDoubleClick" /> <StackPanel Name="spAa" Grid.Row="3" Height="60" HorizontalAlignment="Left" VerticalAlignment="Top" Width="503" Orientation="Horizontal" Background="#FFEBEBFF"> <TextBox Height="23" Name="txbAa" Width="340" Margin="10,0,0,0" FontWeight="Bold" Background="Azure" Text="2clk me" MouseDoubleClick="txbAa_MouseDoubleClick" /> </Grid> </Window>