Click here to Skip to main content
15,867,141 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: default control template xaml Pin
Bob Bedell11-Jul-09 4:08
Bob Bedell11-Jul-09 4:08 
Questiontextbox - select all Pin
teejayem8-Jul-09 6:07
teejayem8-Jul-09 6:07 
AnswerRe: textbox - select all Pin
User 2710099-Jul-09 18:23
User 2710099-Jul-09 18:23 
QuestionMessage Removed Pin
8-Jul-09 3:45
professionalN_tro_P8-Jul-09 3:45 
AnswerRe: WPF Charting Pin
Pete O'Hanlon8-Jul-09 4:41
subeditorPete O'Hanlon8-Jul-09 4:41 
QuestionListview binding is not working with page class Pin
laprathab7-Jul-09 21:50
laprathab7-Jul-09 21:50 
AnswerRe: Listview binding is not working with page class Pin
User 2710097-Jul-09 22:05
User 2710097-Jul-09 22:05 
GeneralRe: Listview binding is not working with page class Pin
laprathab7-Jul-09 23:11
laprathab7-Jul-09 23:11 
Hi Karl,

Page loading with empty listview items from the ObservableCollections.I hv posted my code behind for your reference.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel; 

namespace WPFtest
{
    /// <summary>
    /// Interaction logic for ComboTest.xaml
    /// </summary>
    public partial class ComboTest : Page
    {
      

            private ObservableCollection<GameData> _GameCollection =  new ObservableCollection<GameData>();
            private ObservableCollection<Department> _AvailablePublishers = new ObservableCollection<Department>();
            private ObservableCollection<Role> _AvailableRoles = new ObservableCollection<Role>();
            private GridViewColumnHeader _CurSortCol = null;
            private SortAdorner _CurAdorner = null;

    public ComboTest()
    {
      _GameCollection.Add(new GameData { 
        GameName = "World Of Warcraft", 
        Creator = "Blizzard", 
        Publisher = "Blizzard" });
      _GameCollection.Add(new GameData { 
        GameName = "Halo", 
        Creator = "Bungie", 
        Publisher = "Microsoft" });
      _GameCollection.Add(new GameData { 
        GameName = "Gears Of War", 
        Creator = "Epic", 
        Publisher = "Microsoft" });


      _AvailablePublishers.Add(new Department { DeptID = "1", DeptName = "Purchase" });
      _AvailablePublishers.Add(new Department { DeptID = "2", DeptName = "production" });
      _AvailablePublishers.Add(new Department { DeptID = "3", DeptName = "Inventory" });    
      //_AvailablePublishers.Add("Microsoft");
      //_AvailablePublishers.Add("Blizzard");
      //_AvailablePublishers.Add("Nintendo");
      //_AvailablePublishers.Add("Electronic Arts");
      //_AvailablePublishers.Add("Activision");
      //_AvailablePublishers.Add("Ubisoft");
      //_AvailablePublishers.Add("Take-Two Interactive");

      InitializeComponent();
    }

    public ObservableCollection<GameData> GameCollection
    { get { return _GameCollection; } }

    public ObservableCollection<Department> AvailablePublishers
    { get { return _AvailablePublishers; } }

    public ObservableCollection<Role> AvailableRoles
    { get { return _AvailableRoles ; } }

    private void AddRowClick(object sender, RoutedEventArgs e)
    {
        MessageBox.Show("Hi");  
        _GameCollection.Add(new GameData { 
        GameName = "A New Game", 
        Creator = "A New Creator", 
        Publisher = "<Select A Publisher>" });
    }

    private void SortClick(object sender, RoutedEventArgs e)
    {
      GridViewColumnHeader column = 
          sender as GridViewColumnHeader;
      String field = column.Tag as String;

      if (_CurSortCol != null)
      {
        AdornerLayer.GetAdornerLayer(
            _CurSortCol).Remove(_CurAdorner);
        gameListView.Items.SortDescriptions.Clear();
      }

      ListSortDirection newDir = ListSortDirection.Ascending;
      if (_CurSortCol == column &&
            _CurAdorner.Direction == newDir)
        newDir = ListSortDirection.Descending;

      _CurSortCol = column;
      _CurAdorner = new SortAdorner(_CurSortCol, newDir);
      AdornerLayer.GetAdornerLayer(
          _CurSortCol).Add(_CurAdorner);
      gameListView.Items.SortDescriptions.Add(
          new SortDescription(field, newDir));
    }

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ComboBox cmbTest = sender as ComboBox;
        textBox1.Text = cmbTest.SelectedValue.ToString();
        _AvailableRoles.Add(new Role { RoleID = "1", RoleName = "Executive" });
        _AvailableRoles.Add(new Role { RoleID = "2", RoleName = "Manager" });
    }

    private void btnTest_Click(object sender, RoutedEventArgs e)
    {

        _GameCollection.RemoveAt(1); 
    }
  }

  public class Role : DependencyObject
  {
      public static readonly DependencyProperty role =
           DependencyProperty.Register("roleId", typeof(string),
           typeof(Role), new UIPropertyMetadata(null));

      public string RoleID
      {
          get { return (string)GetValue(role); }
          set { SetValue(role, value); }
      }

      public static readonly DependencyProperty roleNm =
        DependencyProperty.Register("rolenm", typeof(string),
        typeof(Role), new UIPropertyMetadata(null));

      public string RoleName
      {
          get { return (string)GetValue(roleNm); }
          set { SetValue(roleNm, value); }
      }

  }


  public class Department : DependencyObject
  {
      public static readonly DependencyProperty DepartId =
           DependencyProperty.Register("departmentId", typeof(string),
           typeof(Department), new UIPropertyMetadata(null));

      public string DeptID
      {
          get { return (string)GetValue(DepartId); }
          set { SetValue(DepartId, value); }
      }

      public static readonly DependencyProperty DeptNam =
        DependencyProperty.Register("deptName", typeof(string),
        typeof(Department), new UIPropertyMetadata(null));

      public string DeptName
      {
          get { return (string)GetValue(DeptNam); }
          set { SetValue(DeptNam, value); }
      }

  }

  public class GameData : DependencyObject
  {
    public static readonly DependencyProperty GameNameProperty =
      DependencyProperty.Register("GameName", typeof(string), 
      typeof(GameData), new UIPropertyMetadata(null));

    public string GameName
    {
      get { return (string)GetValue(GameNameProperty); }
      set { SetValue(GameNameProperty, value); }
    }

    public static readonly DependencyProperty CreatorProperty =
      DependencyProperty.Register("Creator", typeof(string), 
      typeof(GameData), new UIPropertyMetadata(null));

    public string Creator
    {
      get { return (string)GetValue(CreatorProperty); }
      set { SetValue(CreatorProperty, value); }
    }

    public static readonly DependencyProperty PublisherProperty =
        DependencyProperty.Register("Publisher", typeof(string), 
        typeof(GameData), new UIPropertyMetadata(null));

    public string Publisher
    {
      get { return (string)GetValue(PublisherProperty); }
      set { SetValue(PublisherProperty, value); }
    }
  }

  public class SortAdorner : Adorner
  {
      private readonly static Geometry _AscGeometry =
          Geometry.Parse("M 0,5 L 10,5 L 5,0 Z");
      private readonly static Geometry _DescGeometry =
          Geometry.Parse("M 0,0 L 10,0 L 5,5 Z");

      public ListSortDirection Direction { get; private set; }

      public SortAdorner(UIElement element,
            ListSortDirection dir)
          : base(element)
      { Direction = dir; }

      protected override void OnRender(
          DrawingContext drawingContext)
      {
          base.OnRender(drawingContext);

          if (AdornedElement.RenderSize.Width < 20)
              return;

          drawingContext.PushTransform(
              new TranslateTransform(
                AdornedElement.RenderSize.Width - 15,
                (AdornedElement.RenderSize.Height - 5) / 2));

          drawingContext.DrawGeometry(Brushes.Black, null,
              Direction == ListSortDirection.Ascending ?
                _AscGeometry : _DescGeometry);

          drawingContext.Pop();
      }
  }

  public class BoolToVisibilityConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, 
      object parameter, System.Globalization.CultureInfo culture)
    {
      bool param = bool.Parse(parameter as string);
      bool val = (bool)value;

      return val == param ? 
        Visibility.Visible : Visibility.Hidden;
    }

    public object ConvertBack(object value, Type targetType, 
      object parameter, System.Globalization.CultureInfo culture)
    {
      throw new NotImplementedException();
    }
  }

    
}

GeneralRe: Listview binding is not working with page class Pin
User 2710097-Jul-09 23:17
User 2710097-Jul-09 23:17 
GeneralRe: Listview binding is not working with page class Pin
laprathab7-Jul-09 23:32
laprathab7-Jul-09 23:32 
GeneralRe: Listview binding is not working with page class Pin
User 2710097-Jul-09 23:37
User 2710097-Jul-09 23:37 
GeneralRe: Listview binding is not working with page class Pin
laprathab7-Jul-09 23:47
laprathab7-Jul-09 23:47 
GeneralRe: Listview binding is not working with page class Pin
User 2710097-Jul-09 23:51
User 2710097-Jul-09 23:51 
GeneralRe: Listview binding is not working with page class Pin
laprathab7-Jul-09 23:55
laprathab7-Jul-09 23:55 
GeneralRe: Listview binding is not working with page class Pin
User 2710098-Jul-09 0:05
User 2710098-Jul-09 0:05 
GeneralRe: Listview binding is not working with page class Pin
laprathab8-Jul-09 0:24
laprathab8-Jul-09 0:24 
QuestionHow to use xamDataGrid in VS2005/VS2008 Pin
jgotlt7-Jul-09 20:14
jgotlt7-Jul-09 20:14 
AnswerRe: How to use xamDataGrid in VS2005/VS2008 Pin
User 2710097-Jul-09 21:40
User 2710097-Jul-09 21:40 
GeneralRe: How to use xamDataGrid in VS2005/VS2008 Pin
Pete O'Hanlon7-Jul-09 22:00
subeditorPete O'Hanlon7-Jul-09 22:00 
QuestionElementFlow Intergration - FluidKit Pin
lxmyers7-Jul-09 14:33
lxmyers7-Jul-09 14:33 
QuestionEntity translator Pin
Member 35268517-Jul-09 1:28
Member 35268517-Jul-09 1:28 
AnswerRe: Entity translator Pin
Pete O'Hanlon7-Jul-09 1:36
subeditorPete O'Hanlon7-Jul-09 1:36 
QuestionHow To Host Silver Light User Controls to asp.net Page Contaning webParts Pin
Member 47046757-Jul-09 1:06
Member 47046757-Jul-09 1:06 
AnswerRe: How To Host Silver Light User Controls to asp.net Page Contaning webParts Pin
Not Active7-Jul-09 2:32
mentorNot Active7-Jul-09 2:32 
Questionzoom in WPF- can it wor on a grid as well? Pin
TGiril6-Jul-09 22:44
TGiril6-Jul-09 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.