XAML GridView Datatrigger won't update

72 views Asked by At

I have this XAML in a WPF project.

       <ListView Grid.Column="0" Grid.Row="3" Grid.RowSpan="4" Grid.ColumnSpan="2" ItemsSource="{Binding FilteredApps}" SelectedItem="{Binding SelectedApp, Mode=TwoWay}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Status">
                    <GridViewColumn.CellTemplate >
                        <DataTemplate DataType="{x:Type Image}">
                            <Image>
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding State, Mode=TwoWay}" Value="{x:Static common:Globals+ModelState.Unedited}">
                                                <Setter Property="Source" Value="../Resources/IndraDoc/AppUnedited.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding State, Mode=TwoWay}" Value="{x:Static common:Globals+ModelState.Edited}">
                                                <Setter Property="Source" Value="../Resources/IndraDoc/AppEdited.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding State}" Value="{x:Static common:Globals+ModelState.New}">
                                                <Setter Property="Source" Value="../Resources/IndraDoc/AppNew.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding State}" Value="{x:Static common:Globals+ModelState.Deleted}">
                                                <Setter Property="Source" Value="../Resources/IndraDoc/AppDeleted.png"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>

                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Namn"  Width="Auto"/>
            </GridView>
        </ListView.View>
    </ListView>

When property "Name" changes the appropriate change is displayed in the Grid, but when the property "State" changes the Image is not switched. Any takes on this?

EDIT Strange thing is this, I edited the XAML and added the image outside of the ListView bound it to the SelectedApp instead, this works fine, however that was not the intended functionality. It will work for now, but I am still curious as to why my original code won't trigger.

Adding the code where I do the statechange:

   private void ChangeStateOnSelected(Globals.ModelState newState)
    {
        if (SelectedApp.State != newState) //dont do any changework if new state is same as current sate
        {
            if (SelectedApp.State == Globals.ModelState.New && newState == Globals.ModelState.Edited) //this is not allowed
                return;
            SelectedApp.State = newState;
            if (newState == Globals.ModelState.Unedited)
            {
                var selectedId = SelectedApp.Id;

                _allApps.Replace(_allApps.FirstOrDefault(x => x.Id == SelectedApp.Id), SelectedApp);
                _selectedApp = (Data.DataModel.App)_locationService.GetApp(selectedId);
                _filteredApps.Replace(_filteredApps.FirstOrDefault(x => x.Id == SelectedApp.Id), SelectedApp);
            }
            NotifyOfPropertyChange(() => SelectedApp);
            NotifyOfPropertyChange(() => AllApps);
            NotifyOfPropertyChange(() => FilteredApps);
        }
    }
0

There are 0 answers