Finally, my tiny WPF project is released. It is UV Outliner.
I am a big fan of outliners.
It is astonishing what amount of information in our everyday life has a hierarchical nature.
I always wanted to be able to play with such information. Plans for life or for the day, travel information, meeting schedules, business plans, novels, or even blog posts are all examples of hierarchical information.
So I decided to share the results of my work with other people like me.
I hope UV Outliner will become a part of your life and will help you to be more productive.
http://uvoutliner.com
Четвер, 15 жовтня 2009 р.
Субота, 13 червня 2009 р.
Correct way to keep selection in TextBox and RichTextBox visible after focus lost in WPF
WPF controls: TextBox and RichTextBox have no HideSelection property. Due to this, it is a bit tricky to make them to show selection after focus lost.
There are two possible solutions.
1. Defining separate focus scope in XAML
2. Adding and event handler (LostFocus) and set Handled property of RoutedEventArgs to true in code.
As the second one seems to be tricky, I will show how to implement this behavior with the first concept:
This code will create window with two controls (TextBox and ComboBox):
As you can see, both controls can have focus simultaneously. This happens because of the FocusManager.IsFocusScope property set to true which makes second control to be in a separate focus scope.
However, if new window is opened, focus on both controls will be lost.
You can read more about focus management in WPF here:
http://msdn.microsoft.com/en-us/library/aa969768.aspx
There are two possible solutions.
1. Defining separate focus scope in XAML
2. Adding and event handler (LostFocus) and set Handled property of RoutedEventArgs to true in code.
As the second one seems to be tricky, I will show how to implement this behavior with the first concept:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBox Margin="5">Some text here</TextBox>
<StackPanel Grid.Row="1" FocusManager.IsFocusScope="True">
<ComboBox Margin="5">
<ComboBoxItem IsSelected="True">123</ComboBoxItem>
<ComboBoxItem>123</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
</Window>This code will create window with two controls (TextBox and ComboBox):
As you can see, both controls can have focus simultaneously. This happens because of the FocusManager.IsFocusScope property set to true which makes second control to be in a separate focus scope.However, if new window is opened, focus on both controls will be lost.
You can read more about focus management in WPF here:
http://msdn.microsoft.com/en-us/library/aa969768.aspx
Середа, 11 лютого 2009 р.
How to insert image into FlowDocument at runtime
To insert image into FlowDocument at runtime you can use the following code:
FlowDocument document = new FlowDocument();
Image image = new Image();
BitmapImage bimg = new BitmapImage();
bimg.BeginInit();
bimg.UriSource = new Uri("c:\temp\image.png", UriKind.Absolute);
bimg.EndInit();
image.Source = bimg;
document.Blocks.Add(new BlockUIContainer(image));
Пʼятниця, 7 листопада 2008 р.
How to set initial focus to specific WPF control in XAML
Setting initial focused control in WPF is easy. Just use the FocusManager.FocusedElement attached property:
<Window FocusManager.FocusedElement="{Binding ElementName=MyEdit}" >
<TextBox Name="MyEdit" />
</Window>
Пʼятниця, 24 жовтня 2008 р.
Auto-incremented version in AssemblyInfo
Visual Studio 2008 can increment build version for you. Just specify "*" in the AssemblyInfo.cs. For example:
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyVersion("1.0.0.*")]
Пʼятниця, 17 жовтня 2008 р.
Table-like view in XAML using grid and border
Someone (as I do) may wish to create a table-like layout in XAML as this:

Additionally, I want the thickness of lines to be 1 point everywhere, and I don't want to use FlowDocument.
At first glance it seems to be obvious, however, I have found no straightforward way to implement such layout because of the two reasons:
The code will be like this:

Additionally, I want the thickness of lines to be 1 point everywhere, and I don't want to use FlowDocument.
At first glance it seems to be obvious, however, I have found no straightforward way to implement such layout because of the two reasons:
- Grid has no "border" property
- One cannot create border with invisible side (update: this is not true, read comments below)
The code will be like this:
<Grid Background="#BBBBBB" Margin="18">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2" Margin="1" Background="White" Height="20" SnapsToDevicePixels="True">
<TextBlock Margin="4,2,2,2" VerticalAlignment="Center" Foreground="#666666" HorizontalAlignment="Center">some text</TextBlock>
</Border>
<Border Grid.Row="1" Grid.Column="0" Margin="1,0,0,1" Background="White" Height="50" SnapsToDevicePixels="True">
</Border>
<Border Grid.Row="1" Grid.Column="1" Margin="1,0,1,1" Background="White" Height="50" SnapsToDevicePixels="True">
</Border>
</Grid>
Понеділок, 6 жовтня 2008 р.
PageFunction and attached attribute Resources
It is convenient to embed resources in the page using attached property "Resources". However, due to the bug in XAML parser it is a bit confusing to use this property with PageFunction.
To make it works, you should define Resources property on the Page class instead of PageFunction.
To make it works, you should define Resources property on the Page class instead of PageFunction.
1: <PageFunction>
2: <Page.Resources>
3: ...4: </Page.Resources>
5: 6: ... 7: 8: </PageFunction>
Підписатися на:
Дописи (Atom)