Category Archives: Windows 8

IPhone Basic Memory management

If you’re writing an application for Mac OS X, you have the option to enable garbage collection. In general, this means that you don’t have to think about memory management until you get to more complex cases.

However, you may not always be working with an environment that supports garbage collection. In that case, you need to know a few basic concepts.

If you create an object using the manual alloc style, you need to release the object later. You should not manually release an autoreleased object because your application will crash if you do.

Here are two examples:

// string1 will be released automatically NSString* string1 = [NSString string]; // must release this when done NSString* string2 = [[NSString alloc] init]; [string2 release];

Windows 8: Hide Virtual Keyboard Programmatically

The visibility of the virtual keyboard in Windows 8 Metro Style Apps depends on whether a text input enabled control is focused or not:

In the left image the user tapped into a TextBox control. This tap sets the focus on that TextBox and the virtual keyboard appeared. After having entered some Text the user taps the “OK” button and the virtual keyboard hides again due to the loss of focus (right image).

with-keyboard_thumb1    without-keyboard-copy_thumb1

But sometimes there is no Button control to hit after having entered some text and thus the virtual keyboard does not hide and still might cover important parts of the UI. In order to hide the virtual keyboard no matter where the user taps outside the TextBox one could set the focus to a hidden button programmatically.

See the following example:-

XAML Markup:-

 <Grid>
      <Button x:Name="hiddenButton" Opacity="0" />
      <TextBox Width="300" Margin="50" LostFocus="TextBox_LostFocus" />
 </Grid>

 

C# Code Behind:- 

private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
      this.hiddenButton.Focus(Windows.UI.Xaml.FocusState.Pointer);
}

Happy Programming :-)

Windows 8 ListView Scrolling With SelectedIndex / SelectedItem

For windows 8 ListView Scrolling With SelectedIndex / SelectedItem we can call the method ScrollIntoView(object item) after the ListView is loaded to scroll to the currently selected item. Make sure the control is loaded before you try to make the call

private void itemListView_Loaded(object sender, RoutedEventArgs e)
{
    itemListView.ScrollIntoView(itemListView.SelectedItem);
}

One more example:-
private void btnNextNews_Click(object sender, TappedRoutedEventArgs e)
 {
    CurrentIndex++;
    itemListView.SelectedIndex = CurrentIndex;
    itemListView.ScrollIntoView(LV_NewsDetail.SelectedItem);
}

 

Skip to toolbar