Модераторы: gambit, Kefir, Partizan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Как осущесвить DataTemplate и DataBinding в коде 
:(
    Опции темы
denimm
Дата 6.11.2010, 19:08 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 8.10.2006

Репутация: нет
Всего: нет





Код

ObservableCollection<Tournament> RRR  //Глобальная коллекция


при инициализации 

Код

private void Iniz()
        {
            
            DataTemplate cardLayout = new DataTemplate();
            cardLayout.DataType = typeof(Tournament);
            FrameworkElementFactory spFactory = new FrameworkElementFactory(typeof(StackPanel));
            spFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            

            FrameworkElementFactory Picture = new FrameworkElementFactory(typeof(Image));
            Picture.SetBinding(Image.SourceProperty, new Binding("Picture"));
            Picture.SetValue(Image.MarginProperty, new Thickness(5));
            spFactory.AppendChild(Picture);


            FrameworkElementFactory TextBoxName = new FrameworkElementFactory(typeof(TextBlock));
            TextBoxName.SetBinding(TextBlock.TextProperty, new Binding("Name"));
            TextBoxName.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            TextBoxName.SetValue(TextBlock.VerticalAlignmentProperty , VerticalAlignment.Center);
            TextBoxName.SetValue(Image.MarginProperty, new Thickness(5));           
            spFactory.AppendChild(TextBoxName);


            FrameworkElementFactory TextBoxRegTime = new FrameworkElementFactory(typeof(TextBlock));
            TextBoxRegTime.SetBinding(TextBlock.TextProperty, new Binding("RegTimeStr"));
            TextBoxRegTime.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            TextBoxRegTime.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            TextBoxRegTime.SetValue(Image.MarginProperty, new Thickness(5));           
            spFactory.AppendChild(TextBoxRegTime);


            FrameworkElementFactory TextTimeReg = new FrameworkElementFactory(typeof(TextBlock));
            TextTimeReg.SetBinding(TextBlock.TextProperty, new Binding("RegTimeLeftStr"));
            TextTimeReg.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center);
            TextTimeReg.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center);
            TextTimeReg.SetValue(Image.MarginProperty, new Thickness(5));
            spFactory.AppendChild(TextTimeReg);


            cardLayout.Resources.Add(spFactory, null);
            cardLayout.VisualTree = spFactory;
           
            

            Assembly asm = Assembly.GetExecutingAssembly();
            String[] gt = asm.GetManifestResourceNames();
            Stream PicStream = asm.GetManifestResourceStream(asm.GetName().Name + ".Resources.PicFTP.png");



            BitmapImage Pic = new BitmapImage();
            Pic.BeginInit();
            Pic.StreamSource = PicStream;
            Pic.EndInit();

            DataTemplate rt = new DataTemplate();               

            RRR = new ObservableCollection<Tournament>();            
          
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 12, 05, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 13, 06, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 14, 07, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 15, 08, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 16, 55, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 17, 55, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
            RRR.Add(new Tournament { Name = "Russia Freeroll", Room = PokerRoom.FTP, RegTime = new DateTime(2010, 11, 6, 19, 55, 54), StartTime = new DateTime(2010, 11, 3, 0, 55, 54), IsRegister = false, Picture = Pic });
           

            listBox1.ItemTemplate = cardLayout;
            listBox1.ItemsSource = RRR;
          





при обращении в коде

Код

RRR[0].RegTimeLeftStr = "10:21";
RRR

изменения не происходят


Можно делать так
Код

RRR[0].RegTimeLeftStr = "10:21";
listBox1.Items.Refresh();


но при вызове в таймере через какое-то время все жутко начинает тормозить



Как сделать так чтобы при изменении RRR  менялись значения в listBox1 ???




PM MAIL   Вверх
WolfTheGrey
Дата 9.11.2010, 12:47 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 207
Регистрация: 21.1.2009
Где: forum.vingrad.ru

Репутация: 2
Всего: 2



Использовать INotifyPropertyChanged и в место ObservableColection использовать ListCollectionView

PM MAIL   Вверх
denimm
Дата 10.11.2010, 01:29 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 8.10.2006

Репутация: нет
Всего: нет



Спасибо, коллекцию не менял, помогло добавление  INotifyPropertyChanged
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | WPF и Silverlight | Следующая тема »


 




[ Время генерации скрипта: 0.0411 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.