【问题标题】:Silver Light ComboBox Selected ValueSilver Light ComboBox 选定值
【发布时间】:2014-09-29 07:26:04
【问题描述】:

我在 silverlight 应用程序中有一个组合框,里面有一个复选框和一个文本框,我必须设置 ComboBox 的选定值,但它没有被选中, 我正在关注this 链接,但它不起作用 这是我的组合框

<ComboBox x:Name="Types" SelectedValue="{Binding SelectedType, Mode=TwoWay}"  VerticalAlignment="Top" Margin="2,8,-2,0" Grid.ColumnSpan="3" Height="28" Padding="3">                        
    <ComboBoxItem Tag="All">
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20"/>
                <ColumnDefinition Width="*" MinWidth="105" />
                <ColumnDefinition Width="60" />
            </Grid.ColumnDefinitions>
            <CheckBox  Name="all" VerticalAlignment="Center" Grid.Column="0"/>
            <TextBlock Text="All" VerticalAlignment="Center" Grid.Column="1" Style="{x:Null}" FontSize="11"/>                            
        </Grid>
    </ComboBoxItem>
    <ComboBoxItem Tag="General">
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20"/>
                <ColumnDefinition Width="*" MinWidth="105" />
                <ColumnDefinition Width="60" />
            </Grid.ColumnDefinitions>
            <CheckBox Name="General" VerticalAlignment="Center" Grid.Column="0" />
            <TextBlock Text="General" VerticalAlignment="Center" Grid.Column="1" Style="{x:Null}" FontSize="11"/>
            <TextBox Text="180" VerticalAlignment="Center" Grid.Column="2" FontSize="11" Padding="2" HorizontalContentAlignment="Right"/>
        </Grid>
    </ComboBoxItem>
</ComboBox>

这是我的 SelectedProperty

private string _selectdType = "";
public string SelectedType
{
    get { return _selectdType; }
    set
    {
        _selectdType = value;
        MessageBox.Show(_selectdType);
        NotifyOfPropertyChange("SelectedType");
    }
}

在我的 ViewModel 构造函数中,我是这样设置的

public MyViewModel()
{
    SelectedType="All";
}

但 ComboBox 出现时没有任何选定值(即空白)。 我也尝试使用 Name 属性而不是 Tag 但没有运气

【问题讨论】:

  • 您是否尝试过使用转换器调试绑定..?
  • 不,我是银光新手,我该怎么做?

标签: c# wpf xaml silverlight


【解决方案1】:

您需要为SelectedValue 设置SelectedValuePath 属性才能正常工作:

<ComboBox x:Name="Types" 
          SelectedValuePath="Tag"
          ......
          >
    ......
</ComboBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    相关资源
    最近更新 更多