单击列表框项后WPF选择组合框项

时间:2014-04-08 02:58:03

标签: c# wpf mvvm listbox

我想选择列表框项目,然后将选择组合框项目。以下是我的代码,请检查,谢谢你的帮助。

<Window.Resources>
    <ObjectDataProvider MethodName="GetValues"
                ObjectType="{x:Type sys:Enum}"
                x:Key="GenderDataProvider">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="d:GenderEnum" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>

        <ListBox Name="lbUsers" ItemsSource="{Binding Users}" SelectedItem="{Binding Path=CurrentUser}" DisplayMemberPath="Name" />

            <ComboBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="200" ItemsSource="{Binding Source={StaticResource GenderDataProvider}}" SelectedValue="{Binding Path=CurrentUser.Gender}" />

            <TextBox Name="txtUserName" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="5" Width="200" Text="{Binding Path=CurrentUser.Name}" />

    </StackPanel>
</DockPanel>

1 个答案:

答案 0 :(得分:0)

请替换代码中的以下代码行,让我知道结果。

ComboBox Grid.Row =&#34; 0&#34; Grid.Column =&#34; 1&#34;的Horizo​​ntalAlignment =&#34;左&#34;余量=&#34; 5&#34;宽度=&#34; 200&#34; ItemsSource =&#34; {Binding Source = {StaticResource GenderDataProvider}}&#34; SelectedValue =&#34; {Binding CurrentUser,Path = Gender}&#34; /&GT;

TextBox Name =&#34; txtUserName&#34; Grid.Row =&#34; 1&#34; Grid.Column =&#34; 1&#34;的Horizo​​ntalAlignment =&#34;左&#34;余量=&#34; 5&#34;宽度=&#34; 200&#34; Text =&#34; {Binding CurrentUser,Path = Name}&#34; /&GT;

如果此解决方案没有为您提供预期结果,请详细说明您的要求。