Tuesday, March 20, 2012

AutoCompleteBox KeyPress

I was looking for ways to get enter key in an AutoCompleteBox. But no events supports it. Key Down event of AutoCompleteBox does not trigger the EnterKeyEvent.

Solution:

Create a custom NewAutoCompleteBox then inherit AutoCompleteBox.
Override OnKeyDown
Access the base.OnKeyDown(e); then this will trigger the enter key event.

        if(e.Key == Key.Enter) RaiseEnterKeyDownEvent();



Sunday, March 18, 2012

Expanded ListBoxItem's Width

This will allow element inside to expand its width. 
The key here is in red font. This will allow you to stretch the grid element inside the ListBox. 
-----------------------------------------------------------------------------------------------------
e.g (Maximize Grid element inside  <ListBox.ItemTemplate>  <DataTemplate>  </DataTemplate> </ListBox.ItemTemplate>)
<Grid Width="auto" >
            <Grid.Resources>               
                    <Style x:Key="listContainerStyle" TargetType="ListBoxItem">                     
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>                     
                    </Style>           
            </Grid.Resources> 

          <ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource    listContainerStyle}" ScrollViewer.CanContentScroll="True" ItemsSource="{Binding Path=Model.Object}" Grid.ColumnSpan="2" Grid.Row="1"  Name="lstDiagnosis" >               
                <ListBox.ItemTemplate>                    
                    <DataTemplate>
                        <ListBoxItem HorizontalContentAlignment="Stretch">

                             <Grid Margin="2" >                           
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition Width="50"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <TextBlock FontWeight="Bold" Text="{Binding Name}" Grid.Column="0" >
                            </TextBlock>
                            <TextBlock FontWeight="Bold" Text="{Binding Path=Description}"  Grid.Column="1">
                            </TextBlock>                            
                            <Button HorizontalAlignment="Right" VerticalContentAlignment="Center" VerticalAlignment="Center" Margin="0,0,2,0" Style="{x:Null}" Grid.Column="2"  FontWeight="Bold" FontSize="8" Tag="{Binding}" >
                                <TextBlock Text=" X " VerticalAlignment="Top" ></TextBlock>
                            </Button>
                        </Grid>
            </ListBoxItem>
            </DataTemplate>
            </ListBox.ItemTemplate>
            </ListBox>        
        </Grid>
----------------------------------------------------------------------------------------------------- 




Thursday, March 15, 2012

Self Titled

This is my first blog! :) Hope to enjoy it and if I do, I will create another one for my hobby which is photography. I created this blog to have a collection of information about my work. Latest technologies, codes, programming techniques, software architecture and design, web, windows, tablet and mobile application, gadgets, internet, but not limited to software development. basically everything about 0's and 1's.

This doesn't mean that I'm a savvy with technology, it's just that I need to learn and store more info as possible to survive in this field. This blog will serve as a reference and library of informations from day to day work.