Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / WPF

Getting Started with Facebook Desktop (Client) Applications, C#, WPF / XAML and JSON

Rate me:
Please Sign up or sign in to vote.
4.92/5 (28 votes)
21 Jan 2009CPOL15 min read 319.8K   11.7K   139  
A take on getting started with the Facebook API and WPF
<Window ResizeMode="CanResizeWithGrip" Loaded="FacebookFriendsListWindow_Loaded"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="clr-namespace:Facebook.Properties;assembly=Facebook" 
	x:Class="FacebookApplication.FacebookFriendsList"
	x:Name="FacebookFriendsListWindow"
	Title="Facebook Friends List"
	Width="811.25" Height="481.25" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
    <Window.Resources>
        <!-- Specific style for some buttons -->
        <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="FontFamily" Value="Arial" />
            <Setter Property="FontWeight" Value="Bold" />
            <Setter Property="Width" Value="120" />
            <Setter Property="Height" Value="30" />
            <Setter Property="Margin" Value="1" />
        </Style>
        <!-- End of style for buttons -->

        <!-- Default style for all textboxes -->
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Top" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Height" Value="21" />
            <Setter Property="Width" Value="210" />
            <Setter Property="Margin" Value="2" />
        </Style>
        <!-- End default style for all textboxes -->

        <!-- Default style for all labels -->
        <Style TargetType="{x:Type Label}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Height" Value="25" />
            <Setter Property="Margin" Value="2" />
        </Style>
        <!-- End default style for all labels -->
    </Window.Resources>
    <Grid HorizontalAlignment="Stretch" x:Name="uiGridMain" VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="78"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <!-- Grid row 0 -->
        <Grid HorizontalAlignment="Left" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Application (API Key):"/>
            <TextBox Grid.Row="0" Grid.Column="1" x:Name="uiTbxApplicationKey"  TabIndex="0" Text="{Binding Path=ApplicationKey, Mode=TwoWay, Source={x:Static p:Settings.Default}}"/>
            <Label Grid.Row="1" Grid.Column="0" Content="Facebook Secret:"/>
            <TextBox Grid.Row="1" Grid.Column="1" x:Name="uiTbxSecret" TabIndex="1" Text="{Binding Path=Secret, Mode=TwoWay, Source={x:Static p:Settings.Default}}"/>
            <Label Grid.Row="2" Grid.Column="0" Content="No. of friends to get:"/>
            <TextBox Grid.Row="2" Grid.Column="1" x:Name="uiTbxNumberOfFriends" Width="40" HorizontalAlignment="Left" MaxLength="4" TextAlignment="Center" TabIndex="2" Text="{Binding Path=MaxFriends, Mode=TwoWay, Source={x:Static p:Settings.Default}}"/>
            <Button Grid.Row="0" Name="uiBtnSaveSettings" Grid.Column="2" VerticalAlignment="Center" Height="30" Grid.RowSpan="3" Content="Save Settings" Click="uiBtnSaveSettings_Click" />
        </Grid>
        <StackPanel Grid.Row="0" HorizontalAlignment="Right" Orientation="Vertical" VerticalAlignment="Center">
            <Button x:Name="uiBtnLogin" Style="{StaticResource ButtonStyle}" HorizontalAlignment="Right" Click="uiBtnLogin_Click" Content="Login" />
            <Button x:Name="uiBtnGetFriends" Style="{StaticResource ButtonStyle}" HorizontalAlignment="Right" Content="Get Friends" Click="uiBtnGetFriends_Click" IsEnabled="False" />
        </StackPanel>
        <!-- Grid row 1 -->
        <ListView Grid.Row="1" BorderThickness ="1" BorderBrush="Black" Background="beige" Padding="5" x:Name="uiLvFriends" MinHeight="100" ItemsSource="{Binding}" Margin="2">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
                        <Image Margin="3" Source="{Binding Path=pic_small}" />
                        <StackPanel Margin="3" VerticalAlignment="Center">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock>
                                    <Hyperlink Click="NavigateToUserProfile" NavigateUri="{Binding Path=profile_url}">
                                        <InlineUIContainer>
                                    		<TextBlock FontSize="12" FontWeight="Bold" Text="{Binding Path=full_name}" /> 
                                    	</InlineUIContainer>
                                    </Hyperlink>
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock FontStyle="Italic" Text="Status: "/>
                                <TextBlock Text="{Binding Path=status.status_line}" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <!-- Grid row 2 -->
        <StatusBar Grid.Row="2" Height="20" x:Name="uiSbrStatus" HorizontalAlignment="Stretch">
            <StatusBarItem>
                <TextBlock x:Name="uiTbStatusBarLeft" Text="Status"/>
            </StatusBarItem>
        </StatusBar>
        <!-- End grid row 2 -->
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
You can read more about me here:

http://uk.linkedin.com/in/murrayfoxcroft

Comments and Discussions