0

I've a DataGrid defined as follow:

 private void CreateSemanticChannels()
 {
        myGrid.Style = (Style)FindResource("MyDataGrid");

        var col1 = new DataGridTextColumn
        {
            Header = "FUNCTIONALITY",
            Binding = new Binding("Functionality"),
        };
        myGrid.Columns.Add(col1);

        var col2 = new DataGridTextColumn
        {
            Header = "ASSOCIATED TO",
            Binding = new Binding("AssociatedTo"),
            FontWeight = FontWeights.SemiBold
        };
        myGrid.Columns.Add(col2);

        DataTemplate buttonTemplate = new DataTemplate();
        FrameworkElementFactory buttonFactory = new FrameworkElementFactory(typeof(Button));

        buttonTemplate.VisualTree = buttonFactory;
        var col3 = new DataGridTemplateColumn
        {
            Header = "STATUS",
            CellTemplate = buttonTemplate
        };

        myGrid.Columns.Add(col3);

        // AGGIORNAMENTO CONTENUTO E VISUALIZZAZIONE
        UpdateGrid();
        myGrid.SelectedIndex = -1;
        advSettingGrid.Children.Add(myGrid);

    }

Where in UpdateGrid I add the item to the DataGrid.

myGrid.Items.Add(newRecord);

I want to modify the Style of each Button so I have started following this post but I have always ItemSource empty.

I read this, and actually I forgot to set the ItemSource property. So I defined the List of my object as _recordList and in the XAML I added this property

<Setter Property="BindingGroup" Value="{Binding Path=_recordList}"></Setter>

However, I still have ItemSource empty.

Any help is really appreciate!

Community
  • 1
  • 1
ctt_it
  • 339
  • 1
  • 6
  • 22
  • 1
    Honestly this doesn't look very WPFish. I would rethink your architecture to reduce complexity. You can create the datagrid, style, columns etc all in the xaml and then bind it to your items source. It would greatly reduce the amount of issues that you could be having. – DotNetRussell Jun 14 '16 at 14:15
  • @AnthonyRussell you're right, however this time I have to do it code behind. I solved the problem adding two binding to the TagProperty and IsEnabledProperty of buttonFactory. – ctt_it Jun 16 '16 at 15:17
  • I would tell whomever is telling you to do it in the code behind to by a book on WPF lol – DotNetRussell Jun 16 '16 at 16:55

0 Answers0