My previous post (101 LINQ Samples) refers to very interesting samples. But I didn't pay attention that it is announcement as "future" features. So some of these samples aren't valid (were not implemented).
I'm not one found this trouble, in this forum thread shows what we can use instead of Fold (Aggregate) and EqualAll (SequenceEqual), we should use own realization according to situations for some other operations (SelectMany, Combine).
"Everybody lies" (c) House M.D.
Tuesday, May 12, 2009
Thursday, May 7, 2009
101 LINQ Samples
Sometimes I work with LINQ. So I have completed a task and after some time I should try recall my knowledge of LINQ for new task. It is inconveniently as I should search some info time and again. I have found a great simple LINQ samples. It is very useful and clear for novice. So I can avoid a new recall next time :).
This document locates there - LINQ Samples.
This document locates there - LINQ Samples.
Tuesday, April 21, 2009
Trips&Ticks: Do you know how you can break text in any text control of WPF?
Seems it is easy - we can use a LineBreak in code or as XAML element, but what can we do if we want to present this in attribute of XAML? Little searching shows that we should use XSLT and hexadecimally encoded value to present a literal.<TextBlock Text="Line 1
Line 2" />
Monday, April 13, 2009
Trips&Ticks: Do you know how can you obtain access to nested types through XAML?
Download source files - here.
XAML is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. I have already written how we can obtain access to properties of instance that located in other properties here (I have described binding's potential). But what can we do if we need to access to nested type? Which syntax should me use? It is easy: "+" indicates nested type in XAML:
A lot of code snippets you can see in sources.
XAML is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects. I have already written how we can obtain access to properties of instance that located in other properties here (I have described binding's potential). But what can we do if we need to access to nested type? Which syntax should me use? It is easy: "+" indicates nested type in XAML:local:MultiLevelButton+NestedInfo.NestedNameA lot of code snippets you can see in sources.
Tuesday, March 3, 2009
OnTime desktop light client.
Download source files - here.
Download binary files - here.

My previous customer uses OnTime as bts. It is very slowly tool. I hated it! I tired to wait any respond from this app. I have created a little and more fast tool for self using. This tool ins't complete (I have stopped to work with this customer and I can't have an access to bd for continue implementation).
Next issues need a fix:
If you want to implement some features or to fix bugs you need to know that for correct run sources you need to set connection string in the next files:
Download binary files - here.

My previous customer uses OnTime as bts. It is very slowly tool. I hated it! I tired to wait any respond from this app. I have created a little and more fast tool for self using. This tool ins't complete (I have stopped to work with this customer and I can't have an access to bd for continue implementation).
Next issues need a fix:
- SQL exception isn't handled infrequent :)
- Icons aren't useful. Useful tooltips correct this defect ;)
- Attachment download works in some thread that GUI (It is shameful, but I haven't had time, really)
- App works readonly.
- Sort and Search hasn't implemented.
- We can work with self issues only.
- It is really more fast tool than official.
- Persist state doesn't store in bd. It saves in current PC only.
If you want to implement some features or to fix bugs you need to know that for correct run sources you need to set connection string in the next files:
- app.config
- Settings.Designer.cs
- OTData.dbml
- and Settings.settings in two points.
Tuesday, February 3, 2009
Trips&Ticks: Do you know how you can extract various instances of one object out of resources in WPF?
Download source files - here
I often use a style&template that is magnificent possibility of WPF. It allows to define one style out of resources to many elements. I can easily define instance of some object in resources and extract it there where I require. But it has one limitation:For example for following:
XAML:
<Button x:Key="ButtonPrototype" />
C#:
Resources["ButtonPrototype"]; - returns always one instance (like Singlton Pattern). But what can I make if I require more than one such object? It isn't problem as XAML is very flexible and x:Shared attribute eliminates this trouble. Following code will extract various instances:XAML:
<Button x:Key="ButtonPrototype" x:Shared="False" />
C#
Resources["ButtonPrototype"]PS: In my opinion last realization shares traits with Prototype Pattern.
Saturday, January 10, 2009
Bind to many method simultaneously. Binding in WPF part 2.
Download source files - hereDownload binary files - here
Target:
We have some views that have as source one shared collection. They are located in any ItemsControls (ListBoxs in my case). Those views pass form different parametrized methods (we use the ObjectDataProvider and bind to a method possibility for this purposes). How can we implement one control element's property for affect on those views? We have restricts - it is needed to make in XAML code.
Problem:
How can we pass a value of control element as parameter in bind to a methods?
Solution:
First of all we should declare some (I used "two", so I will write in next time "two" instead of "some") ObjectDataProvider objects.
<ObjectDataProvider ObjectType="{x:Type local:CItems}"
MethodName="GetMax" x:Key="max" >
<ObjectDataProvider.MethodParameters>
<system:Int32>3</system:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider ObjectType="{x:Type local:CItems}"
MethodName="GetMin" x:Key="min" >
<ObjectDataProvider.MethodParameters>
<system:Int32>3</system:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
Bind those objects to views:
<ListBox ItemsSource="{Binding Source={StaticResource min}}" />
<ListBox ItemsSource="{Binding Source={StaticResource max}}" />
Now we need to create a binding to control element's property that has affect to both those data provider. We use MultiBinding with Mode is set OneWayToSource for this purpose. We should implement Converter of MultiBinding. Since we set Mode as OneWayToSource we need only ConvertBack method:
public Object[] ConvertBack( Object value, Type[] targetTypes, Object parameter, CultureInfo culture )
{
Int32 cnt = targetTypes.Length;
Object[] result = new Object[ cnt ];
String str = value.ToString();
if( !String.IsNullOrEmpty( str ) )
{
Int32 index = Int32.Parse( value.ToString() );
for( Int32 i = 0; i < cnt; ++i )
{
result[ i ] = index;
}
}
return result;
}Note: We should unbox value to Int32 other case value isn't correctly passed to method of data provider.
Now we can easy implement this MultiBinding our XAML code:
<ComboBox.Text>
<MultiBinding Mode="OneWayToSource" Converter="{StaticResource artfull}">
<Binding Source="{StaticResource max}"
Path="MethodParameters[0]"
BindsDirectlyToSource="true"
UpdateSourceTrigger="PropertyChanged"
/>
<Binding Source="{StaticResource min}"
Path="MethodParameters[0]"
BindsDirectlyToSource="true"
UpdateSourceTrigger="PropertyChanged"
/>
</MultiBinding>
</ComboBox.Text>
Now when Text property of ComboBox is changed that views will be updated. Easy and nice :). If some details isn't clear - source and binary files were attached in the beginning of article.
Subscribe to:
Posts (Atom)