Belajardengan.com merupakan domain blog lama dari delajardengan.blogspot.com. Mohon kritik dan sarannya untuk perkembangan blog ini.
email: blog.tkx.pnp@gmail.com

Windows Phone || Contoh Simple Binding List

♠ Posted by aan ganas in at 4:27 AM

Contoh Simple Binding List Windows Phone

MainPage.xaml
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Command="{Binding Tambah}" Content="Button" HorizontalAlignment="Left" Margin="336,-126,0,0" VerticalAlignment="Top"/>
            <ListBox ItemsSource="{Binding L_classnama}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Width="400" Background="Goldenrod" Margin="0,0,0,5">
                            <!-- Binding Source Gambar -->
                            <Image Margin="20,0,0,0" Height="60" Width="60" Source="{Binding Gambar}"></Image>
                            <!-- Binding TextBlock -->
                            <TextBlock Text="{Binding Nama}" TextWrapping="Wrap" FontSize="30" Style="{StaticResource PhoneTextExtraLargeStyle}" FontFamily="Comic Sans MS"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

MainPage.xaml.cs

public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            DataContext = new MAinPageViewModle();
        }
    }


MAinPageViewModle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace Bi
{
    class MAinPageViewModle : Microsoft.Practices.Prism.ViewModel.NotificationObject
    {
        public List<ClassNama> L_classnama{get;set;}
        private Microsoft.Practices.Prism.Commands.DelegateCommand _tambah;
        void TambahAction() {
            L_classnama = new List<ClassNama>();
            L_classnama.Add(new ClassNama() { Nama = "xxxx", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "xx", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "xxx", Gambar = "unduhan.jpg" });
            Console.WriteLine("asssssssssssssssssssssssssssss");
            RaisePropertyChanged("");
        }
        public Microsoft.Practices.Prism.Commands.DelegateCommand Tambah
        {
            get { return _tambah; }
        }
        public MAinPageViewModle(){
            _tambah = new Microsoft.Practices.Prism.Commands.DelegateCommand(TambahAction);
            L_classnama = new List<ClassNama>();
            L_classnama.Add(new ClassNama() { Nama = "asdasdas" ,Gambar="unduhan.jpg"});
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
            L_classnama.Add(new ClassNama() { Nama = "asdasdas", Gambar = "unduhan.jpg" });
        }
    }  
}
 
ClassNama

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bi
{
    class ClassNama  : Microsoft.Practices.Prism.ViewModel.NotificationObject
    {
        private string _nama;
        private string _gambar;
        public string Nama { get { return _nama; } set { _nama = value; RaisePropertyChanged(""); } }
        public string Gambar { get { return _gambar; } set { _gambar = value; RaisePropertyChanged(""); } }
    }
}





1 komentar:

public void AddData()
{
ListofBookmarkedSurah.Clear();
SearchResult.Clear();
int no = 1;
if (_quranConfigurationService.SelectedBookMark.Count != 0)
{
var xx = _quranConfigurationService.ListOfSurah;
var xx2 = _quranConfigurationService.SelectedBookMark;
var Temp = from p1 in _quranConfigurationService.SelectedBookMark
join p2 in _quranConfigurationService.ListOfSurah
on p1.ItemNumberOfSurah equals p2.noSurah
orderby p1.DateTimeOfBookMark descending
select p2;

foreach(var data in Temp)
{
if (data.noSurah <= 1) //preloaded surah = 1
{
data.surahColor = "#FF2D3F4C";
}
else
{
if (selectedLanguage == "en")
{
if (data.imageExist && data.translationExist_en && data.transliterationExist_en)
{
data.surahColor = "#FF2D3F4C";
}
else
{
data.surahColor = "Gray";
}
}
else if (selectedLanguage == "id")
{
if (data.imageExist && data.translationExist_id && data.transliterationExist_id)
{
data.surahColor = "#FF2D3F4C";
}
else
{
data.surahColor = "Gray";
}

}
}
SearchResult.Add(data);
}

applicationBarVisibility = true;
//foreach (var data in _quranConfigurationService.SelectedBookMark.OrderByDescending(x => x.DateTimeOfBookMark))
//{
// data.No = no++;
// ListofBookmarkedSurah.Add(data);
//}
foreach (var data in _quranConfigurationService.SelectedBookMark.OrderByDescending(x => x.DateTimeOfBookMark))
{
foreach (var dataTemp in SearchResult)
{
if(dataTemp.noSurah == dataTemp.noSurah)
{
data.BackgroundSelected = dataTemp.surahColor;
break;
}

}
ListofBookmarkedSurah.Add(data);
}
}
else
{
applicationBarVisibility = false;
noBookmarkData = Islamic_Services.Quran.Resources.AppResource.ISLAMIC_SERVICES_QURAN_NOBOOKMARK;
}
RaisePropertyChanged("");
}

Post a Comment