27
Mar
 
C# Code
namespace DataBindingTutorial
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        inetaPakistanDataContext dc;
        Presenter ps;

        public MainWindow()
        {
            dc = new inetaPakistanDataContext();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            PopulatePresenters();
        }

        private void PopulatePresenters()
        {
            var presenters = from p
                             in dc.Presenters
                             select p;

            ddlPresenters.ItemsSource = presenters;
            ddlPresenters.DisplayMemberPath = "FullName";
            ddlPresenters.SelectedValuePath = "PresenterId";
        }

        private void ddlPresenters_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int id = Convert.ToInt32(ddlPresenters.SelectedValue);

            ps = (from p
                      in dc.Presenters
                  where p.PresenterId == id
                  select p).Single();
            myGrid.DataContext = ps;
        }

        private void btnAddRanking_Click(object sender, RoutedEventArgs e)
        {
            ps.Ranking += 1;
        }

        private void btnShowRanking_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(ps.Ranking.ToString());
        }
    }
}
XAML Code
<Grid Name="myGrid" ...>
   <TextBox Text="{Binding Path=Ranking}" Name="txtRanking" ... />
   <TextBox Text="{Binding Path=CoreCompetency}" Name="txtCoreCompetency" ... />
</Grid>

Tags:

Categories: WPF

blog comments powered by Disqus