public DataGrid MakeUserListTemplate() { DataGrid dg = (DataGrid)XamlReader.Parse( " <DataGrid CanUserResizeRows=\"False\" CanUserReorderColumns=\"False\" Margin=\"0\" Padding=\"0\" CanUserAddRows=\"False\" EnableColumnVirtualization=\"True\" EnableRowVirtualization=\"True\" CanUserDeleteRows=\"False\" Background=\"Transparent\" AutoGenerateColumns=\"False\" SelectionMode=\"Single\">" + " <DataGrid.ContextMenu>" + " <ContextMenu>" + " <MenuItem Name=\"Chat\" Header=\"Chat with this user\"></MenuItem>" + " <MenuItem Name=\"Conversation\"></MenuItem>" + " <MenuItem Name=\"Group\" Header=\"Group\"></MenuItem>" + " <MenuItem Name=\"Ignore\"></MenuItem>" + " <MenuItem Name=\"TUS\"></MenuItem>" + " <MenuItem Name=\"Info\"></MenuItem>" + " </ContextMenu>" + " </DataGrid.ContextMenu>" + " <DataGrid.Columns>" + " <DataGridTemplateColumn Header=\"C.\" IsReadOnly=\"True\" SortMemberPath=\"Country\" Width=\"32\">" + " <DataGridTemplateColumn.CellTemplate>" + " <DataTemplate>" + " <Image HorizontalAlignment=\"Left\" Margin=\"4,0,0,0\" VerticalAlignment=\"Center\" ToolTip=\"{Binding Path=Country.Name, Mode=OneWay}\" Source=\"{Binding Path=Country.Flag, Mode=OneWay}\" Width=\"22\" Height=\"18\"></Image>" + " </DataTemplate>" + " </DataGridTemplateColumn.CellTemplate>" + " </DataGridTemplateColumn>" + " <DataGridTemplateColumn Header=\"Rank\" IsReadOnly=\"True\" SortMemberPath=\"Rank\" Width=\"58\">" + " <DataGridTemplateColumn.CellTemplate>" + " <DataTemplate>" + " <Image HorizontalAlignment=\"Left\" VerticalAlignment=\"Center\" ToolTip=\"{Binding Path=Rank.Name, Mode=OneWay}\" Margin=\"0\" Source=\"{Binding Path=Rank.Picture, Mode=OneWay}\" Width=\"48\" Height=\"17\"></Image>" + " </DataTemplate>" + " </DataGridTemplateColumn.CellTemplate>" + " </DataGridTemplateColumn>" + " <DataGridTemplateColumn Header=\"Nick\" IsReadOnly=\"True\" SortMemberPath=\"Name\" Width=\"3*\">" + " <DataGridTemplateColumn.CellTemplate>" + " <DataTemplate>" + " <TextBlock HorizontalAlignment=\"Left\" VerticalAlignment=\"Center\" Foreground=\"AliceBlue\" FontSize=\"13\" Text=\"{Binding Path=Name, Mode=OneWay}\" Style=\"{DynamicResource ClientNameStyle}\">" + " <TextBlock.Resources>" + " <Style x:Key=\"ClientNameStyle\" TargetType=\"TextBlock\">" + " <Style.Triggers>" + " <DataTrigger Binding=\"{Binding Path=TusActive}\" Value=\"true\">" + " <Setter Property=\"TextDecorations\" Value=\"Underline\" />" + " </DataTrigger>" + " <DataTrigger Binding=\"{Binding Path=GreatSnooper}\" Value=\"true\">" + " <Setter Property=\"FontStyle\" Value=\"Italic\" />" + " </DataTrigger>" + " </Style.Triggers>" + " </Style>" + " </TextBlock.Resources>" + " </TextBlock>" + " </DataTemplate>" + " </DataGridTemplateColumn.CellTemplate>" + " </DataGridTemplateColumn>" + " <DataGridTemplateColumn Header=\"Clan\" IsReadOnly=\"True\" SortMemberPath=\"Clan\" Width=\"2*\">" + " <DataGridTemplateColumn.CellTemplate>" + " <DataTemplate>" + " <TextBlock HorizontalAlignment=\"Left\" Foreground=\"AliceBlue\" VerticalAlignment=\"Center\" FontSize=\"12\" Text=\"{Binding Path=Clan, Mode=OneWay}\"></TextBlock>" + " </DataTemplate>" + " </DataGridTemplateColumn.CellTemplate>" + " </DataGridTemplateColumn>" + " <DataGridTemplateColumn Header=\"Info\" IsReadOnly=\"True\" SortMemberPath=\"ClientApp\" Width=\"3*\">" + " <DataGridTemplateColumn.CellTemplate>" + " <DataTemplate>" + " <TextBlock HorizontalAlignment=\"Left\" Foreground=\"AliceBlue\" VerticalAlignment=\"Center\" FontSize=\"12\" Text=\"{Binding Path=ClientApp, Mode=OneWay}\"></TextBlock>" + " </DataTemplate>" + " </DataGridTemplateColumn.CellTemplate>" + " </DataGridTemplateColumn>" + " </DataGrid.Columns>" + " </DataGrid>" , GlobalManager.XamlContext); dg.MinRowHeight = 0; dg.RowHeight = 18; dg.RowStyle = (Style)UserList.FindResource("DataGridRowStyle"); dg.ColumnHeaderStyle = (Style)UserList.FindResource("DataGridColumnHeaderStyle"); dg.LostFocus += ClientList_LostFocus; dg.MouseDoubleClick += PrivateMessageClick; dg.SelectionChanged += NoSelectionChange; dg.Sorting += dg_Sorting; ((MenuItem)dg.ContextMenu.Items[0]).Click += PrivateMessageClick2; ((MenuItem)dg.ContextMenu.Items[1]).Click += AddOrRemoveClientConversation; ((MenuItem)dg.ContextMenu.Items[3]).Click += AddOrRemoveBan; ((MenuItem)dg.ContextMenu.Items[4]).Click += WiewTusProfile; dg.ContextMenuOpening += ContextMenuBuilding; dg.PreviewMouseUp += dg_MouseUp; if (!Properties.Settings.Default.ShowInfoColumn) { dg.Columns[4].Visibility = System.Windows.Visibility.Collapsed; } SetClientListDGColumns(dg); foreach (var column in dg.Columns) { DataGridColumn.ActualWidthProperty.AddValueChanged(column, delegate { if (changing || Mouse.LeftButton == MouseButtonState.Released) { return; } changing = true; }); } return(dg); }