简体   繁体   English

无法在“ ListView”中设置“ comboBox”的选定值

[英]unable to set selected value of “comboBox” in “ListView”

I am unable to set selected value of "comboBox" in "ListView". 我无法在“ ListView”中设置“ comboBox”的选定值。

Here is XAML code. 这是XAML代码。

Propertyname: LISTTOPICS 属性名: 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 C#代码是

public class SelectedTopic : ObservableObject
{
    private static string selectedTopic;
    public static string SELECTEDTOPIC
    {
        get { return selectedTopic; }
        set { selectedTopic = value; }
    }
}

您需要在设置器中调用RaisePropertyChanged。

You have two options (it's difficult to say precisely, because DataContext isn't clear from your question): 您有两个选择(很难说清楚,因为您的问题不清楚DataContext):

  1. change binding expression to something like SelectedValue="{Binding SELECTEDTOPIC}" . 将绑定表达式更改为SelectedValue="{Binding SELECTEDTOPIC}"
  2. properly binds to static property: Binding to static class property . 正确绑定到静态属性: 绑定到静态类property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM