本文主要是介绍DataGrid中DataGridComboBoxColumn列SelectedValueBinding注意Mode设置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天在使用DataGrid的下拉列表列时因设置SelectedValueBinding="{Binding 触发沿, Mode=OneWay}"
,导致下拉列表一直无法显示,查找半天最后发现将Mode改成TwoWay
,问题解决。
<DataGrid VerticalAlignment="Stretch" x:Name="dgItems"Height="Auto"SelectionUnit="FullRow" SelectionMode="Extended" CanUserAddRows="False"DataContext="{Binding}" Width="Auto" AutoGenerateColumns="False"FontSize="16" AlternatingRowBackground="LightBlue"AlternationCount="2" Margin="10, 10" Background="Transparent"ScrollViewer.VerticalScrollBarVisibility="Visible"><DataGrid.Resources><col:ArrayList x:Key="key_triggerList"><col:DictionaryEntry Key="上升沿" Value="上升沿"/><col:DictionaryEntry Key="下降沿" Value="下降沿"/></col:ArrayList><col:ArrayList x:Key="key_attenuatorList"><col:DictionaryEntry Key=" 0dB" Value="0"/><col:DictionaryEntry Key="20dB" Value="20"/><col:DictionaryEntry Key="40dB" Value="40"/><col:DictionaryEntry Key="60dB" Value="60"/></col:ArrayList></DataGrid.Resources><DataGrid.Columns><DataGridTextColumn Header="IP" Width="120*" Binding="{Binding IP, Mode=OneWay}" /><DataGridComboBoxColumn Header="触发沿" Width="80*" IsReadOnly="False" DisplayMemberPath="Key" SelectedValuePath="Value" SelectedValueBinding="{Binding 触发沿, Mode=TwoWay}" ItemsSource="{StaticResource key_triggerList}"/><DataGridTextColumn Header="触发电平(V)" IsReadOnly="False" Width="80*" Binding="{Binding 触发电平, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /><DataGridComboBoxColumn Header="衰减器" IsReadOnly="False" Width="80*" DisplayMemberPath="Key" SelectedValuePath="Value" SelectedValueBinding="{Binding 衰减器, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{StaticResource key_attenuatorList}"/></DataGrid.Columns>
</DataGrid>
注意在xaml的<window/>
节增加
<window xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"></window>
这篇关于DataGrid中DataGridComboBoxColumn列SelectedValueBinding注意Mode设置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!