0

I am unable to set selected value of "comboBox" in "ListView".

Here is XAML code.

Propertyname: LISTTOPICS

<ListView x:Name="gridTopics" 
          ItemsSource="{Binding Path=TOPICSINFO}" Width="310">
    <ListView.View>
        <GridView>
            <GridView.Columns>
                <GridViewColumn Header="Associated Topics" >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding LISTTOPICS}" 
                                      SelectedValue="{Binding SelectedTopic.SELECTEDTOPIC}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>

And C# code is

public class SelectedTopic : ObservableObject
{
    private static string selectedTopic;
    public static string SELECTEDTOPIC
    {
        get { return selectedTopic; }
        set { selectedTopic = value; }
    }
}
Vladimir Almaev
  • 2,358
  • 1
  • 28
  • 38
Ahsan
  • 648
  • 1
  • 10
  • 27

2 Answers2

0

You need to call RaisePropertyChanged in your setter.

Mark Feldman
  • 15,731
  • 3
  • 31
  • 58
0

You have two options (it's difficult to say precisely, because DataContext isn't clear from your question):

  1. change binding expression to something like SelectedValue="{Binding SELECTEDTOPIC}" .
  2. properly binds to static property: Binding to static class property.
Community
  • 1
  • 1
Vladimir Almaev
  • 2,358
  • 1
  • 28
  • 38