-1

Right now I have a table (SelectedModule.Vwr) that updates when the selected module changes.

 <ContentControl x:Name="MainTableCtrl" Content="{Binding SelectedModule.Vwr, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0"/>

What I`d like to do is filter the table in the code behind. So instead of binding directly to the table, I would bind to a filtered table.

public MainTableViewModel FilteredMain
{
    get { //filter results here
          return SelectedModule.Vwr; }
    set { }
}

I'm having some trouble with the tables updating however. The table doesn't update it's display properly anymore. Once SelectedModule changes, FilteredMain still displays the original table.

I'd like to know how to tell the UI to update it's source again once an event happens. In this case that source would be FilteredMain, and the event would be SelectedModule changing

Tristan
  • 96
  • 13
  • 1
    You are misunderstanding what `UpdateSourceTrigger=PropertyChanged` is doing. It is meant to control how the source property of a TwoWay or OneWayToSource is updated when the target property changes. This is not relevant in your Binding. The setting has no effect on the (OneWay) Binding of the Content property of a ContentControl. – Clemens Feb 12 '18 at 14:54
  • you're right. Do you know then how I would make it call get on FilteredMain again when selectedModule changes? – Tristan Feb 12 '18 at 15:03
  • Have you tried MVVM? [Link how to implement MVVM](https://stackoverflow.com/questions/1405739/mvvm-tutorial-from-start-to-finish) – Nenad Feb 12 '18 at 15:26
  • It's already MVVM? – Tristan Feb 12 '18 at 15:28
  • SelectedModule.Vwr.Tbl is the DataTable. I'd just like to know how to tell the UI to update it's source again once an event happens. In this case that source would be FilteredMain, and the event would be SelectedModule changing – Tristan Feb 12 '18 at 16:21

1 Answers1

0

Does anyone know how I would go about triggering it to update the source when SelectedModule changes from the code behind?

Listen to the DataTable Events and raise the PropertyChanged event for the FilteredMain property whenever any is raised:

public partial class MainWindow : Window, INotifyPropertyChanged
{
    public MainWindow()
    {
        InitializeComponent();

        ...
        dataTable.RowChanged += (ss, ee) => 
        {
            //invoke the getter of the FilteredMain
            NotifyPropertyChanged("FilteredMain");
        };
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    ...
}

You will need to implement the INotifyPropertyChanged interface for this to work.

mm8
  • 163,881
  • 10
  • 57
  • 88