顯示具有 [Programming]Windows Store apps 標籤的文章。 顯示所有文章
顯示具有 [Programming]Windows Store apps 標籤的文章。 顯示所有文章

2014年1月7日 星期二

[Java, Windows 8] How to transform Java List to Store apps C++/CX?

Java codes:

private static List<String> vv = new ArrayList<String>();

vv.add("area");
vv.add("base");
vv.add("basefont");
vv.add("br");
vv.add("col");
vv.add("frame");
vv.add("hr");
vv.add("img");
vv.add("input");
vv.add("isindex");
vv.add("link");
vv.add("meta");
vv.add("param");

String ss = "hr";
if (vv.contains(ss))
{
/* vv contains ss */
}
else
{
/* vv does not contain xx */
}

==> Store apps C++/CX
Platform::Collections::Vector<Platform::String^>^ vv = ref new Vector<Platform::String^>();

vv->Append("area");
vv->Append("base");
vv->Append("basefont");
vv->Append("br");
vv->Append("col");
vv->Append("frame");
vv->Append("hr");
vv->Append("img");
vv->Append("input");
vv->Append("isindex");
vv->Append("link");
vv->Append("meta");
vv->Append("param");

unsigned int index = 0;
String^ ss = "hr";
if (vv->IndexOf(ss, &index))
{
/* vv contains ss */
else
{
/* vv does not contain xx */
}

2013年6月20日 星期四

[Windows 8] How to set TextBlock and TextBox to wrap in XAML

TextBlock and TextBox by setting TextWrapping = "Wrap" attribute to make the text exceeds the width of the control automatically wrap. The default is nowrap.
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>


2013年6月18日 星期二

[Windows 8] How to check windows 8 UI modes by C#

Sample:

using Windows.UI.ViewManagement;

private void pageRoot_SizeChanged(object sender, SizeChangedEventArgs e)
{
    ApplicationViewState viewState = ApplicationView.Value;
    if (viewState == ApplicationViewState.Filled)
    {
        System.Diagnostics.Debug.WriteLine("viewState is Filled");
    }
    else if (viewState == ApplicationViewState.FullScreenLandscape)
    {
        System.Diagnostics.Debug.WriteLine("viewState is FullScreenLandscape");
    }
    else if (viewState == ApplicationViewState.Snapped)
    {
        System.Diagnostics.Debug.WriteLine("viewState is Snapped");
    }
    else if (viewState == ApplicationViewState.FullScreenPortrait)
    {
        System.Diagnostics.Debug.WriteLine("viewState is FullScreenPortrait");
    }
    else
    {
        System.Diagnostics.Debug.WriteLine("viewState is something unexpected");
    }
}

[Windows 8] How to create a circle mask image with XAML

The example creates an ImageBrush and sets the ImageSource to an image named people.png, which you must include as a resource in the app. The ImageBrush then paints the area defined by an Ellipse shape.
<Ellipse Height="200" Width="200"> 
    <Ellipse.Fill> 
        <ImageBrush ImageSource="people.png" /> 
    </Ellipse.Fill> 
</Ellipse>

Result:

Reference:
Quickstart: Using brushes (Windows Store apps using C#/VB/C++ and XAML)

2013年5月30日 星期四

[Windows 8] How to show message dialog in Windows 8 store app

You can use the MessageDialog class to Represents a dialog.
    public sealed class MessageDialog : Object
If you don't specify any commands, then a default command is added to close the dialog.

Sample

private async void testButton_Click(object sender, RoutedEventArgs e)
{
    // Create the message dialog and set its content
    var messageDialog = new MessageDialog("No internet connection has been found.");

    // Show the message dialog
    await messageDialog.ShowAsync();
}
Result:

You want to add custom commands by Commands.Add.

Sample

private async void testButton_Click(object sender, RoutedEventArgs e)
{
    // Create the message dialog and set its content
    var messageDialog = new MessageDialog("No internet connection has been found.");

    // Add commands and set their callbacks; both buttons 
    // use the same callback function instead of inline event handlers
    messageDialog.Commands.Add(new UICommand("Try again", 
        new UICommandInvokedHandler(this.doTryAgain)));
    messageDialog.Commands.Add(new UICommand("Close",
        new UICommandInvokedHandler(this.doClose)));

    // Set the command that will be invoked by default
    messageDialog.DefaultCommandIndex = 0;

    // Set the command to be invoked when escape is pressed
    messageDialog.CancelCommandIndex = 1;

    // Show the message dialog
    await messageDialog.ShowAsync();
}

private void doTryAgain(IUICommand command)
{
    // do something
}

private void doClose(IUICommand command)
{
    // do something
}

Result:

Reference:
MessageDialog class

2013年5月21日 星期二

[Windows 8] How to make Metro ListView selection color modification in XAML

Add the following xaml tag
    <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#FF8FC249"/> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#DE8FC249"/> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#AB8FC249"/>

to StandardStyles.xaml file, and reference the following:
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    
    <!-- Non-brush values that vary across themes --> 
    
    <ResourceDictionary.ThemeDictionaries> 
        <ResourceDictionary x:Key="Default"> 
            <x:String x:Key="BackButtonGlyph"></x:String> 
            <x:String x:Key="BackButtonSnappedGlyph"></x:String> 
        </ResourceDictionary> 
        
        <ResourceDictionary x:Key="HighContrast"> 
            <x:String x:Key="BackButtonGlyph"></x:String> 
            <x:String x:Key="BackButtonSnappedGlyph"></x:String> 
        </ResourceDictionary> 
    </ResourceDictionary.ThemeDictionaries> 
    
    <x:String x:Key="ChevronGlyph"></x:String> 
    
    <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="#FF8FC249"/> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="#DE8FC249"/> 
    <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="#AB8FC249"/>
    ...
</ResourceDictionary> 

2013年5月14日 星期二

[Windows 8] To fix error: Additional information: Cannot perform runtime binding on a null reference

Recently, in the study the Facebook API, try to find a feed/data, but I feed data no contents, run the following program, there will be the Additional Information: Can not perform runtime binding on a null reference ":
  dynamic feeds = await fbClient.GetTaskAsync(strID + "?fields=feed");
  foreach (var data in feeds.feed.data)
  {
     ...
  }
Later changed to:
  dynamic feeds = await fbClient.GetTaskAsync(strID + "/feed");
  if (feeds != null)
  {
    foreach (var data in feeds.data)
    {
       ...
    }
  }
The problem is solved.

2013年5月12日 星期日

[Windows 8] How to set the Item to bring into view with ListView in Windows Store app

You can use the following function:

Scrolls the list to bring the specified data item into view.
public void ScrollIntoView(
    object item
)

Parameters

item
          Type: System.Object [.NET] | Platform::Object [C++]
          The data item to bring into view.

Sample

    int nPos = 5;  
    listView.ItemsSource = list;
    listView.UpdateLayout();
    listView.ScrollIntoView(list[nPos]);

2013年5月11日 星期六

[Windows 8] 工作上遇到的問題: 如何在未安裝 Visual Studio 2012 的機器上測試 Windows Store App

使用Google
Search: windows store app 如何package

找到一篇不錯的文章:
    如何在未安裝 Visual Studio 2012 的機器上測試 Windows Store App
    http://blogs.msdn.com/b/mengtsai/archive/2013/03/05/visual-studio-2012-windows-store-app.aspx

2013年4月26日 星期五

[Windows 8] How to design a 2 column XAML ListView in Windows 8 Store App

The WrapGrid replaces the default VirtualizingStackPanel, which arranges items in a single column. To set the WrapGrid.MaximumRowsOrColumns property is arranged in 2 columns.

XAML file

<ListView Height="320" Width="260">
    <ListView.ItemsPanel> 
       <ItemsPanelTemplate> 
          <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2"/>
       </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    
    <Rectangle Height="100" Width="100" Fill="Blue" />
    <Rectangle Height="100" Width="100" Fill="Red" />
    <Rectangle Height="100" Width="100" Fill="Yellow" /> 
    <Rectangle Height="100" Width="100" Fill="Green" /> 
    <Rectangle Height="100" Width="100" Fill="Gray" /> 
    <Rectangle Height="100" Width="100" Fill="LightBlue" />
    <Rectangle Height="100" Width="100" Fill="Pink" /> 
    <Rectangle Height="100" Width="100" Fill="YellowGreen" /> 
</ListView>

Result:

Reference:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh780650.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3

[Windows 8] How to remove all items with ListView / GridView in Windows 8 Store Apps by C#

    itemsList.Clear();         // 1, Remove data list
    uiElement.ItemsSource = null;  // 2. set ListView / GridView 
                                 //    ItemSource to null
    uiElement.Items.Clear();       // 3. clear ListView / GridView items

2013年4月23日 星期二

[Windows 8] How to show or hide the components with windows store app by C#

Example

private void PlayMedia(object sender, MouseButtonEventArgs args)
{
    pauseBTN.Visibility = Visibility.Visible;
    playBTN.Visibility = Visibility.Collapsed;

    media.SpeedRatio = 1.0;
    media.Play();
}

XAML Attribute Usage

<uiElement Visibility="Visible" .../>
or
<uiElement Visibility="Collapsed" .../>
The default value is Visible

UIElement.Visibility Property

Member name
Description
Visible Display the element.
Collapsed Do not display the element

reference:

[Windows 8] How to create a login screen in Windows Store App by C#


Today, I will show you how to create a login screen in Windows Style Application by C#.

The result in the following shown:
Firstly, create the xaml page and add the codes:

<Page x:Class="FacebookDemo.FacebookLogin" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:FacebookDemo" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d">

    <ContentControl x:Name="container" Height="450" Margin="0,194,0,124">
        <Popup x:Name="logincontrol" IsOpen="False" >
           <StackPanel Orientation="Vertical" Background="#3F000000" Height="400" x:Name="pop" > 
               <WebView Name="WebView" Width="450" Height="400" Loaded="WebView_Loaded" /> 
           </StackPanel>
        </Popup>
    </ContentControl>
</Page>

and then add the codes into xaml.cs construct:
namespace FacebookDemo
{
    public sealed partial class FacebookLogin : Page
    {
 ...
        public FacebookLogin()
        {
     ... 
            this.InitializeComponent();

            container.IsEnabled = true;
            logincontrol.IsOpen = true;
            pop.Width = Window.Current.Bounds.Width;
        }
 ...
    }
}

Secondly, I add the codes to show popup windows in the main page:
namespace FacebookDemo
{
    ...
    public sealed partial class MainPage : FacebookDemo.Common.LayoutAwarePage
    {
 ...
        Popup popup = new Popup();
        public MainPage()
        {
            this.InitializeComponent();
            popup.Child = new FacebookLogin();
            popup.VerticalOffset = 0;
            popup.HorizontalOffset = 0;
            popup.Width = Window.Current.Bounds.Width;
            popup.Height = Window.Current.Bounds.Height;

            popup.IsOpen = true;
            IsEnabled = false;
            App.fbevents.FBEvent += fbevents_FBEvent;
     ...
        }
        ...
        void fbevents_FBEvent(object sender, string accesscode)
        {
            IsEnabled = true;
            ...
        }
    }
}

When the popup windows is shown, the main page should set IsEnable to false. When the popup windows is closed, the main page must set  IsEnable to true.

[Windows 8] How to use the timer in the Windows Store Application by C#

// defines
private DispatcherTimer _timer;

// Init
_timer= new DispatcherTimer();
_timer.Tick += _timer_Tick;
_timer.Interval = new TimeSpan(0, 0, 1);

...
_timer.Start();                 // start timer


private void _timer_Tick(object sender, object e)
{
   // do something
}

_timer.Stop();                 // stop timer
_timer.Tick -= _timer_Tick;    // delete function reference

Reference:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dispatchertimer(v=win.10).aspx