- Маршрутизация событий и визуальные деревья
- Маршрутизация команд
- Избежание проблем с фокусировкой команд
- Выход за рамки маршрутизированных команд
Roman Pelepei gives smart answers on questions about C# .Net, ASP .Net, WPF and Silverlight programming with examples and source code.
среда, 24 февраля 2010 г.
Знакомство с маршрутизированными событиями и командами в WPF
вторник, 23 февраля 2010 г.
Inconsistent accessibility: field type 'type' is less accessible than field 'field'
class MyClass
// try the following line instead
// public class MyClass
{
}
public class MyClass2
{
public MyClass mf; // CS0052
}
Multiple Window Interface for WPF
Working with Checkboxes in the WPF TreeView
TreeView
whose items contain checkboxes. Each item is bound to a ViewModel object. When a ViewModel object’s check state changes, it applies simple rules to the check state of its parent and child items. This article also shows how to use the attached behavior concept to turn a TreeViewItem
into a virtual ToggleButton
, which helps make the TreeView
’s keyboard interaction simple and intuitive. http://www.codeproject.com/KB/WPF/TreeViewWithCheckBoxes.aspx
понедельник, 22 февраля 2010 г.
Настройка отображения данных с привязкой данных и WPF
- Привязка данных в технологии WPF
- Отображение данных и иерархические данные
- Использование шаблонов
- Проверка ввода
вторник, 16 февраля 2010 г.
Как сделать ОДНУ страницу альбомной, когда все остальные в документе книжные в Word?
понедельник, 8 февраля 2010 г.
Grouping Data with the ListView Control
DataSourceID="ProductDataSource"
GroupItemCount="3" ItemPlaceholderID="itemsGoHere"
GroupPlaceholderID="groupsGoHere">
<LayoutTemplate>
<p>
<asp:PlaceHolder runat="server" ID="groupsGoHere"></asp:PlaceHolder>
</p>
</LayoutTemplate>
<GroupTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemsGoHere"></asp:PlaceHolder>
</ol>
</GroupTemplate>
<ItemTemplate>
<li><%#Eval("ProductName")%></li>
</ItemTemplate>
</asp:ListView>
String Format for Double [C#]
The following examples show how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString.
Digits after decimal point
This example formats double to string with fixed number of decimal places. For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded.
[C#]// just two decimal places
String.Format("{0:0.00}", 123.4567); // "123.46"
String.Format("{0:0.00}", 123.4); // "123.40"
String.Format("{0:0.00}", 123.0); // "123.00"
Next example formats double to string with floating number of decimal places. E.g. for maximal two decimal places use pattern „0.##“.
[C#]// max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4); // "123.4"
String.Format("{0:0.##}", 123.0); // "123"
Digits before decimal point
If you want a float number to have any minimal number of digits before decimal point use N-times zero before decimal point. E.g. pattern „00.0“ formats a float number to string with at least two digits before decimal point and one digit after that.
[C#]// at least two digits before decimal point
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567); // "23.5"
String.Format("{0:00.0}", 3.4567); // "03.5"
String.Format("{0:00.0}", -3.4567); // "-03.5"
Thousands separator
To format double to string with use of thousands separator use zero and comma separator before an usual float formatting pattern, e.g. pattern „0,0.0“ formats the number to use thousands separators and to have one decimal place.
[C#]String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67); // "12,346"
Zero
Float numbers between zero and one can be formatted in two ways, with or without leading zero before decimal point. To format number without a leading zero use # before point. For example „#.0“ formats number to have one decimal place and zero to N digits before decimal point (e.g. „.5“ or „123.5“).
Following code shows how can be formatted a zero (of double type).
[C#]String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
Align numbers with spaces
To align float number to the right use comma „,“ option before the colon. Type comma followed by a number of spaces, e.g. „0,10:0.0“ (this can be used only in String.Format method, not indouble.ToString method). To align numbers to the left use negative number of spaces.
[C#]String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
Custom formatting for negative numbers and zero
If you need to use custom format for negative float numbers or zero, use semicolon separator„;“ to split pattern to three sections. The first section formats positive numbers, the second section formats negative numbers and the third section formats zero. If you omit the last section, zero will be formatted using the first section.
[C#]String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
Some funny examples
As you could notice in the previous example, you can put any text into formatting pattern, e.g. before an usual pattern „my text 0.0“. You can even put any text between the zeroes, e.g. „0aaa.bbb0“.
[C#]String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3" String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"
See also
- [C#] String Format for Int – format (align) integer numbers
- [C#] String Format for DateTime – format date and time
- [C#] IFormatProvider for Numbers – format and parse float numbers using CultureInfo
- [C#] Custom IFormatProvider – string formatting with custom IFormatProvider
- [C#] Align String with Spaces – how to align text to the right or left
- [C#] Indent String with Spaces – how to indent text with repeated spaces
- MSDN Examples – MSDN examples for custom numeric formatting
- String.Format – MSDN – method to format strings
- Double.ToString – MSDN – formats double to string
воскресенье, 7 февраля 2010 г.
Comparing two byte arrays in .NET
1 | byte [] array1 = new byte [] { 1, 2, 3, 4 }; |
2 | byte [] array2 = new byte [] { 1, 2, 3, 4 }; |
3 |
4 | bool areEqual = array1.SequenceEqual(array2); //returns true |
Simple concatenating byte arrays in .NET
byte[] combined = bytesOne.Concat(bytesTwo).Concat(bytesThree).ToArray();