0 Replies - 3231 Views - Last Post: 07 December 2011 - 05:27 AM

#1 jp612  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 16-August 11

Creating a strike through effect listbox

Posted 07 December 2011 - 05:27 AM

Hi,

Im creating a visual list in my app, what i want to do is implement a checklist function where a user can cross out an item on the list however it seems that this cant be achieved with text decorations. So i want to draw it manually.

Im using a ObservableCollection and a ListBox to display the collection.

How exactly would i go about drawing a line through a specific element in a listBox?? I can add and remove items so far.

  public MainPage()
        {
            InitializeComponent();
            
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.Opacity = 1.0;
            ApplicationBar.IsVisible = true;
            ApplicationBar.IsMenuEnabled = true;

            ApplicationBarIconButton bAdd = new ApplicationBarIconButton();
            bAdd.IconUri = new Uri("/Images/appbar.add.rest.png", UriKind.Relative);
            bAdd.Text = "Add Item";
            ApplicationBar.Buttons.Add(bAdd);
            bAdd.Click += new EventHandler(bAdd_Click);

            ApplicationBarIconButton bDel = new ApplicationBarIconButton();
            bDel.IconUri = new Uri("/Images/appbar.minus.rest.png", UriKind.Relative);
            bDel.Text = "Remove Item";
            ApplicationBar.Buttons.Add(bDel);
            bDel.Click += new EventHandler(bDel_Click);

            ApplicationBarIconButton bClear = new ApplicationBarIconButton();
            bClear.IconUri = new Uri("/Images/appbar.delete.rest.png", UriKind.Relative);
            bClear.Text = "Clear List";
            ApplicationBar.Buttons.Add(bClear);
            bClear.Click += new EventHandler(bClear_Click);
            
            list = new ObservableCollection<string>();
            listBox1.ItemsSource = list;
            
        }

        private void bDel_Click(object sender, EventArgs e)
        {
            try
            {
                list.RemoveAt(listBox1.SelectedIndex);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show("Error: Please select a valid item to delete!");
            }
      
        }

        private void bClear_Click(object sender, EventArgs e)
        {
            list.Clear();
            MessageBox.Show("list Cleared");
           
        }


        void button1_Click(object sender, RoutedEventArgs e)
        {      
            try
            {
                String item = b1.Text;
                if (item.Length <= 0)
                {
                    throw new System.ArgumentException("Error: Please enter valid values.");
                }

                list.Add(item);  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
               
            // Close the popup.
            p.IsOpen = false;
            currWinOpen = false;
            
        }





Above is a example of how i use the Listbox.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1