<ScrollViewer.Resources>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">5</sys:Double>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarButtonHeightKey}">5</sys:Double>
<sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">5</sys:Double>
<sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}">3</sys:Double>
</ScrollViewer.Resources>
Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts
Tuesday, May 28, 2013
SelfNote: ListBox scroll bar size
Tuesday, January 22, 2013
SelfNote: Convert rendered location to actual value
Learn something new everyday. :-)
Today I got a solution to get the rendered location for an object which has be RenderTransform-ed.
The trick is to use MatrixConverter to perform the conversion.
Today I got a solution to get the rendered location for an object which has be RenderTransform-ed.
The trick is to use MatrixConverter to perform the conversion.
Friday, March 23, 2012
F# 3.0 CLIMutable Attribute
If you have ever been working with XAML with some designer support, you will be additive to the benefit brought by designer. I'd spend weeks without implementing any feature and work on designer support. One scenario is described here. Default constructor is the key! Unfortunately, the record type in F# does not have a default constructor by default and it makes binding difficult.
Now we have CLIMutable to solve this problem. The screenshot for CLIMutable is below:
If you define the following F# code:
then in the C# code you can do
The type R has the default constructor while R2, which is not decorated with CLIMutable, does not have the default constructor.
Hopefully this 3.0 feature can make your UI work a little easier. :-)
Now we have CLIMutable to solve this problem. The screenshot for CLIMutable is below:
If you define the following F# code:
[ < CLIMutable > ]
type R =
{ X: int; Y:int }
type R2 =
{ X: int; Y:int }
then in the C# code you can do
var x = new R();
var x2 = new R(0, 2);
var y = new R2(0, 2);
// var y2 = new R2(); //does not compile
The type R has the default constructor while R2, which is not decorated with CLIMutable, does not have the default constructor.
Hopefully this 3.0 feature can make your UI work a little easier. :-)
Tuesday, September 6, 2011
WPF/SilverLight F# Converter
Since 2006 I started to develop WPF application, I experienced the pain of writing XAML, binding, converter, coerce, and the MVVM pattern. I find the F# is the best tool to write converters. I can still recall somebody was trying to write some framework to chain some multiple converters. I published a snippet on http://fssnip.net/7Q.
First of all, let me justify converter is still useful when MVVM pattern is available. First application of converter is for graphic designers. The converter provide graphic designer some basic mathematically tool to design a control. The MVVM pattern is too much for a graphic designer. Secondly, the MVVM itself can use converter as well. The last point is how big is your project. I would not say MVVM pattern is suitable for a small demo project. Use the right tool at the right time to do the right job is the key.
The converter snippet design idea is simple. It groups the functions into a module and function composition and pipeline can chain different function and form a new function. The converter basically is a function, you can use strategy pattern (http://fssnip.net/7k) as the starting point to design a converter.
The hard part is how to make your function look like (object, type, object, cultureInfo) format. The following function is the function to convert your function to (object, type, object,cultureInfo) signature.
First of all, let me justify converter is still useful when MVVM pattern is available. First application of converter is for graphic designers. The converter provide graphic designer some basic mathematically tool to design a control. The MVVM pattern is too much for a graphic designer. Secondly, the MVVM itself can use converter as well. The last point is how big is your project. I would not say MVVM pattern is suitable for a small demo project. Use the right tool at the right time to do the right job is the key.
The converter snippet design idea is simple. It groups the functions into a module and function composition and pipeline can chain different function and form a new function. The converter basically is a function, you can use strategy pattern (http://fssnip.net/7k) as the starting point to design a converter.
The hard part is how to make your function look like (object, type, object, cultureInfo) format. The following function is the function to convert your function to (object, type, object,cultureInfo) signature.
let convert<'T> f (obj:System.Object) (t:Type) (para:System.Object) (culture:Globalization.CultureInfo) = (obj :?> 'T) |> f |> boxThe concrete implementation is to chain up different function to form a string to visibility as convert function and nullFunction as convertBack function. The converter is trying to reduce the coding effort and make sure the generated code can work with Blend. I added another converter which I used a lot in my data binding debugging. The converter itself does not do anything, but can be used to check if the binding actually work or not.
Thursday, August 19, 2010
Use Style to keep the WPF tree's selection state
< TreeView.Resources >
< Style TargetType="{x:Type TreeViewItem}" >
< Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/ >
< Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/ >
< /Style>
< / TreeView.Resources >
also need to put event handler:
private void OnTreeViewItemExpanded(object sender, RoutedEventArgs e)
{
TreeViewItem tvi = e.OriginalSource as TreeViewItem;
tvi.IsSelected = true;
if (tvi.IsExpanded)
tvi.Focus();
}
< Style TargetType="{x:Type TreeViewItem}" >
< Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/ >
< Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/ >
< /Style>
< / TreeView.Resources >
also need to put event handler:
private void OnTreeViewItemExpanded(object sender, RoutedEventArgs e)
{
TreeViewItem tvi = e.OriginalSource as TreeViewItem;
tvi.IsSelected = true;
if (tvi.IsExpanded)
tvi.Focus();
}
Subscribe to:
Posts (Atom)
