我有一個組合框,顯示列表視圖在下拉列表中,我遵循MVVM模式,我也設置公共屬性在我的Viewmodel,它工作正常,當我分配給標籤,但爲Combobox似乎不依賴於我的綁定。我嘗試了很多方法,但無法找到問題。組合框和列表視圖綁定問題wpf c#
XAML:
<ComboBox Name="SearchBox" IsEditable="True" Background="White" md:HintAssist.Hint="Search MUID" Grid.Column="1" Margin="5 0 0 0"
Grid.Row="0" Height="40" Width="400" HorizontalContentAlignment="Left" HorizontalAlignment="Left" SelectedItem="{Binding ElementName=lstview ,Path=SelectedItem}" >
<ComboBoxItem>
<ListView x:Name="lstview" ItemsSource="{Binding filterSW}"
SelectedItem="{Binding SelectedMU}"
Height="200" ScrollViewer.VerticalScrollBarVisibility="Visible">
<ListView.View>
<GridView>
<GridViewColumn Width="130" Header="Mu-ID" />
<GridViewColumn Width="130" Header="MU-Identifier" DisplayMemberBinding="{Binding MU_Identifier}" />
<GridViewColumn Width="130" Header="Status" DisplayMemberBinding="{Binding RequestType}" />
<GridViewColumn Width="130" Header="UniqueID" />
</GridView>
</ListView.View>
</ListView>
</ComboBoxItem>
</ComboBox>
這對我工作得很好,當我使用的是公共財產和訪問其元素,我也嘗試設置文本= {結合SelectedMU.MU_Identifier}和的SelectedValue但它只是不工作。
<Label Grid.Column="3" HorizontalAlignment="Center" Background="GreenYellow" Content="{Binding SelectedMU.MU_Identifier}"></Label>
你的綁定對Combobox來說有點奇怪。爲什麼要將ListView注入到單個ComboBox項目中?爲什麼要有一個ComboBox? –