MainPage.xaml
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal">
<sdk:DataGrid Name="grid" Margin="10" AutoGenerateColumns="False">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<sdk:DataGridTextColumn Header="Age" Binding="{Binding Age}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<StackPanel>
<sdk:DataGrid Name="gBooks" Margin="10" AutoGenerateColumns="False" DataContext="{Binding SelectedItem, ElementName=grid}" ItemsSource="{Binding Books}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Title" Binding="{Binding Title}" />
<sdk:DataGridTextColumn Header="Code" Binding="{Binding Code}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<StackPanel DataContext="{Binding SelectedItem, ElementName=grid}" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<CheckBox IsChecked="{Binding isMale}" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
CodeBehind:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
grid.ItemsSource = GridData.GetData();
}
}
public class GridData
{
public string Name { get; set; }
public int Age { get; set; }
public bool isMale { get; set; }
public IEnumerable<Book> Books { get; set; }
public class Book
{
public string Title { get; set; }
public string Code { get; set; }
};
public static ObservableCollection<GridData> GetData()
{
ObservableCollection<GridData> data = new ObservableCollection<GridData>
{
new GridData { Name = "John Doe", Age = 30, isMale = true,
Books = new List<Book> {
new Book {Title = "suits", Code = "123"},
new Book {Title = "Condors 1", Code = "113"}
}
},
new GridData { Name = "Jane Doe", Age = 32, isMale = false },
new GridData { Name = "Jason Smith", Age = 54, isMale = true },
new GridData { Name = "Kayli Jayne", Age = 25, isMale = false}
};
return data;
}
}
Saturday, July 28, 2012
Saturday, July 21, 2012
windows azure user
create login username with password = 'password'; (on master)
create user username for login username; (on database)
exec sp_addrolemember 'db_owner', 'username'
create user username for login username; (on database)
exec sp_addrolemember 'db_owner', 'username'
Saturday, July 14, 2012
Longest Increasing Sequence C#
static public int LongestIncreasingSeq(int[] s) {
int[] l = new int[s.Length]; // DP table for max length[i]
int[] p = new int[s.Length]; // DP table for predeccesor[i]
int max = int.MinValue;
l[0] = 1;
for (int i=0; i<s.Length; i++)
p[i] = -1;
for (int i = 1; i < s.Length; i++)
{
l[i] = 1;
for (int j = 0; j < i; j++)
{
if (s[j] < s[i] && l[j] + 1 > l[i])
{
l[i] = l[j] + 1;
p[i] = j;
if (l[i] > max)
max = l[i];
}
}
}
return max;
}
Linear Partition in C#
static public void partition(int[] s, int n, int k) {
Console.Write("{");
Utils.printArray(s);
Console.WriteLine("}");
int MAXN = s.Length;
int MAXK = 3;
int[,] m = new int[MAXN, MAXK]; // DP table for values.
int[,] d = new int[MAXN, MAXK]; // DP table for dividers.
int[] p = new int[MAXN]; // prefix sums array.
int cost;
p[0] = s[0];
for (int i = 1; i < n; i++) p[i] = p[i - 1] + s[i];
for (int i = 0; i < n; i++) m[i, 0] = p[i];
for (int j = 0; j < k; j++) m[0, j] = s[0];
for (int i = 1; i < n; i++)
for (int j = 1; j < k; j++)
{
m[i, j] = int.MaxValue;
for (int x = 0; x <= (i - 1); x++)
{
cost = Math.Max(m[x, j - 1], p[i] - p[x]);
if (m[i, j] > cost)
{
m[i, j] = cost;
d[i, j] = x + 1;
}
}
}
Console.Write("{");
reconstruct_particion(s, d, n, k);
Console.Write("} ");
}
private static void reconstruct_particion(int[] s, int[,] d, int n, int k)
{
if (k == 1)
{
print_books(s, 0, n);
}
else
{
reconstruct_particion(s, d, d[n - 1, k - 1], k - 1);
print_books(s, d[n - 1, k - 1], n);
}
}
private static void print_books(int[] s, int start, int end)
{
Console.Write("{");
for (int i = start; i < end; i++)
Console.Write(" {0} ", s[i]);
Console.Write("} ");
}
Thursday, June 28, 2012
There is a known issue in the WCF Services SDK which may soon cause you at least a really annoying message; "this operation is not supported for a relative uri". While it is not fatal and you can ignore it – as a matter of good coding, I tend to get rid of as many warning messages as possible. To fix it, open your machine.config (both x86 and x64 version), and delete the following section:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
<endpoint address="" binding="netTcpRelayBinding"
contract="IMetadataExchange" name="sb" />
Wednesday, January 18, 2012
Presenting Storyboard View Controllers Programmatically
Although the storyboard runtime usually handles transitions between view controllers, you can also trigger segues programmatically from your code. You might do so when setting up the segue in Interface Builder is not possible, such as when using accelerometer events to trigger the transition. There are several options for transitioning to a new view controller:
- If a storyboard file contains an existing segue between the current view controller and the destination view controller (perhaps triggered by some other control in the view controller), you can trigger that segue programmatically using the
performSegueWithIdentifier:sender:method ofUIViewController. - If there is no segue between the view controllers but the destination view controller is defined in the storyboard file, first load the view controller programmatically using the
instantiateViewControllerWithIdentifier:method ofUIStoryboard. Then present the view controller using any of the existing programmatic means, such as by pushing it on a navigation stack. - If the destination view controller is not in the storyboard file, create it programmatically and present it as described in View Controller Programming Guide for iOS.
Friday, December 16, 2011
iphone element sizes
Core Elements:
Carrier Status bar - 320x20
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44
Data Input:
UIPickerView - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216
Buttons:
UISegmentedControl - 320x44
UIButton xx37
UIButton xx37
Fields:
UITextField - xx37
UISwitch 94x27
UISlider - xx23
UISwitch 94x27
UISlider - xx23
Indicators:
UIProgressView -xx9
UIActivityIndicatorView - 37x37
UIPageControl - 38x36
UIActivityIndicatorView - 37x37
UIPageControl - 38x36
Subscribe to:
Posts (Atom)