public TabItem MakeGameListTabItem(Channel channel) { TabItem ti = new TabItem(); Grid grid = (Grid)XamlReader.Parse( " <Grid>" + " <Grid.RowDefinitions>" + " <RowDefinition Height=\"34\" />" + " <RowDefinition Height=\"3\" />" + " <RowDefinition Height=\"*\" />" + " </Grid.RowDefinitions>" + " <Border Grid.Row=\"0\" BorderThickness=\"1,0,1,1\" BorderBrush=\"Gray\" Background=\"#123456\">" + " <DockPanel>" + " <Canvas DockPanel.Dock=\"Left\" Visibility=\"{Binding Path=CanHostVisibility, Mode=OneWay}\">" + " <StackPanel Canvas.Left=\"0\" Orientation=\"Horizontal\">" + " <Button Content=\"Host a game\" Focusable=\"False\" Height=\"33\" Background=\"Black\" BorderThickness=\"0,0,1,0\" Padding=\"15,0\" />" + " <Button Content=\"Refresh game list\" Focusable=\"False\" Height=\"33\" Background=\"Black\" BorderThickness=\"0,0,1,0\" Padding=\"15,0\" />" + " </StackPanel>" + " </Canvas>" + " <Canvas DockPanel.Dock=\"Right\" Visibility=\"{Binding Path=LeaveChannelVisibility, Mode=OneWay}\">" + " <Button Canvas.Right=\"0\" Height=\"33\" Background=\"Black\" BorderThickness=\"1,0,0,0\" Content=\"Leave this channel\" Focusable=\"False\" Padding=\"15,0\" />" + " </Canvas>" + " <StackPanel Orientation=\"Horizontal\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\">" + " <TextBlock /> " + " <TextBlock Visibility=\"{Binding Path=LeaveChannelVisibility, Mode=OneWay}\" Text=\" | \" /> " + " <TextBlock Visibility=\"{Binding Path=LeaveChannelVisibility, Mode=OneWay}\" /> " + " <TextBlock Visibility=\"{Binding Path=LeaveChannelVisibility, Mode=OneWay}\" Text=\" Users\" /> " + " <TextBlock Visibility=\"{Binding Path=CanHostVisibility, Mode=OneWay}\" Text=\" | \" /> " + " <TextBlock Visibility=\"{Binding Path=CanHostVisibility, Mode=OneWay}\" /> " + " <TextBlock Visibility=\"{Binding Path=CanHostVisibility, Mode=OneWay}\" Text=\" Games\" /> " + " </StackPanel>" + " </DockPanel>" + " </Border>" + " <Border Grid.Row=\"2\">" + " <ListBox HorizontalContentAlignment=\"Stretch\" Background=\"Transparent\">" + " <ListBox.ItemContainerStyle>" + " <Style TargetType=\"ListBoxItem\">" + " <Setter Property=\"Height\" Value=\"20\" />" + " </Style>" + " </ListBox.ItemContainerStyle>" + " <ListBox.ItemTemplate>" + " <DataTemplate>" + " <Grid Background=\"Transparent\">" + " <Grid.ColumnDefinitions>" + " <ColumnDefinition Width=\"22\" />" + " <ColumnDefinition Width=\"22\" />" + " <ColumnDefinition Width=\"240\" />" + " <ColumnDefinition Width=\"150\" />" + " </Grid.ColumnDefinitions>" + " <Image Grid.Column=\"0\" VerticalAlignment=\"Center\" Source=\"{Binding Path=Locked, Mode=OneWay}\" Width=\"16\" Height=\"16\" Margin=\"0,0,6,0\"></Image>" + " <Image Grid.Column=\"1\" Source=\"{Binding Path=Country.Flag, Mode=OneWay}\" ToolTip=\"{Binding Path=Country.Name, Mode=OneWay}\" Width=\"22\" Height=\"18\" Margin=\"0,0,6,0\"></Image>" + " <TextBlock Grid.Column=\"2\" FontSize=\"13\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Center\" Foreground=\"White\" Text=\"{Binding Path=Name, Mode=OneWay}\" />" + " <TextBlock Grid.Column=\"3\" FontSize=\"13\" HorizontalAlignment=\"Left\" VerticalAlignment=\"Center\" Foreground=\"White\" Text=\"{Binding Path=Hoster, Mode=OneWay}\" />" + " </Grid>" + " </DataTemplate>" + " </ListBox.ItemTemplate>" + " <ListBox.ContextMenu>" + " <ContextMenu>" + " <MenuItem Header=\"Join this game\"></MenuItem>" + " <MenuItem Header=\"Silent join\"></MenuItem>" + " <MenuItem Header=\"Join and close snooper\"></MenuItem>" + " <MenuItem Header=\"Silent join and close snooper\"></MenuItem>" + " </ContextMenu>" + " </ListBox.ContextMenu>" + " </ListBox>" + " </Border>" + " </Grid>" , GlobalManager.XamlContext); ti.Content = grid; ti.DataContext = channel; DockPanel dp = (DockPanel)((Border)grid.Children[0]).Child; StackPanel sp = (StackPanel)((Canvas)dp.Children[0]).Children[0]; Button hostBt = (Button)sp.Children[0]; hostBt.Click += GameHosting; Button refreshBt = (Button)sp.Children[1]; refreshBt.Click += RefreshClick; Button leaveChannelBt = (Button)((Canvas)dp.Children[1]).Children[0]; leaveChannelBt.Click += LeaveChannel; StackPanel tbsp = (StackPanel)dp.Children[2]; TextBlock channelNameTB = (TextBlock)tbsp.Children[0]; channelNameTB.Text = channel.Name; TextBlock userListTB = (TextBlock)tbsp.Children[2]; Binding b1 = new Binding("ClientCount"); b1.Source = channel; b1.Mode = BindingMode.OneWay; userListTB.SetBinding(TextBlock.TextProperty, b1); TextBlock gameListTB = (TextBlock)tbsp.Children[5]; Binding b2 = new Binding("GameCount"); b2.Source = channel; b2.Mode = BindingMode.OneWay; gameListTB.SetBinding(TextBlock.TextProperty, b2); ListBox lb = (ListBox)((Border)grid.Children[1]).Child; lb.ItemContainerStyle = (Style)GameList.FindResource("ListBoxItemStyle"); lb.MouseDoubleClick += GameDoubleClick; lb.SelectionChanged += NoSelectionChange; lb.LostFocus += GameList_LostFocus; ((MenuItem)lb.ContextMenu.Items[0]).Click += JoinGameClick; ((MenuItem)lb.ContextMenu.Items[0]).Tag = lb; ((MenuItem)lb.ContextMenu.Items[1]).Click += SilentJoin; ((MenuItem)lb.ContextMenu.Items[1]).Tag = lb; ((MenuItem)lb.ContextMenu.Items[2]).Click += JoinAndClose; ((MenuItem)lb.ContextMenu.Items[2]).Tag = lb; ((MenuItem)lb.ContextMenu.Items[3]).Click += SilentJoinAndClose; ((MenuItem)lb.ContextMenu.Items[3]).Tag = lb; return(ti); }