Quantcast
Channel: wpftoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 2157

New Post: (very) Basic Databinding question

$
0
0
Hi all! I have a novice question that I can't seem to find quite the right answer to. I'm following the tutorial found here. I can't seem to get the DataGridCollectionViewSource to correctly bind to a property in my app. Here's my XAML, basically a copy and past from the tutorial:
<Grid x:Name="factorGrid" xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid" HorizontalAlignment="Left" Height="406" Margin="346,64,0,0" VerticalAlignment="Top" Width="350" Background="#FFD1CCCC">
            <Grid.Resources>
                <xcdg:DataGridCollectionViewSource x:Key="key_factors" Source="{Binding Source={x:Static Application.Current}, Path=FactorSet }"/>
            </Grid.Resources>
            <xcdg:DataGridControl x:Name="FactorsGrid" ItemsSource="{Binding Source={StaticResource key_factors}}"/>
        </Grid>
Nothing is showing up when I run my app - however, in the VS xaml screen, I can see the squiggly line under Path=FactorSet, and hovering over it says : "Cannot resolve property FactorSet in data context of type 'System.Windows.Application'

And here's part of my class (VS 2015, c#) - I have abbreviated and removed things not relevant to the question. I could be approaching this the wrong way (I'm still learning!), so suggestions are appreciated. (I'm also trying to learn how to implement MVC. So if that looks way, waaay off... well, I'm still learning :) )
public partial class MainWindow : Window, IObserver<ResearchFactor>
    {
        private string _designSelection;
        private IController _controller;
        List<ResearchFactor> _factors;
        private static DataTable factorSet;
        
        public static DataTable FactorSet => factorSet;
public MainWindow()
        {
            //InitializeComponent();
            
        }

        public MainWindow(string designSelection, IModel model, IController controller)
        {
            InitializeComponent();
            _factors = new List<ResearchFactor>();
            _designSelection = designSelection;
            designLabel.Content += designSelection;
            _controller = controller;
            updateFactorList();
        }
//more code
internal void updateFactorList()
        {
            factorSet = CreateDataTable();
            DataGridControl dgControl = new DataGridControl
            {
                ItemsSource = new DataGridCollectionView(FactorSet.DefaultView)
            };
        }
public DataTable CreateDataTable()
        {

            ///this part sets up the structure of the datatable           
            Type entityType = typeof(ResearchFactor);
            DataTable dt = new DataTable(entityType.Name);
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(entityType);

            foreach (PropertyDescriptor prop in properties)
            {
                dt.Columns.Add(prop.Name, prop.PropertyType);
            }

            //now we need to add the data to the table.
            foreach (ResearchFactor factor in _factors)
            {
                DataRow row = dt.NewRow();

                foreach (PropertyDescriptor prop in properties)
                {
                    row[prop.Name] = prop.GetValue(factor);
                }
            }
            
            return dt;
        }
Could it be that my class is not static?

Thanks for the help!

Viewing all articles
Browse latest Browse all 2157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>