我正在使用DataGrid。一列显示文本,但其后面的数据仅包含一个id。必须以某种方式将此id转换为字符串。
我需要具有属性 ItemsSource , DisplayMemberPath , SelectedValue 和 SelectedValuePath 的组合框。但是,不是显示按钮,而是必须只有文本。对此有一些控制吗?
有效(想要用看起来像文本框的东西交换组合框):
<DataGridTemplateColumn Header="Leistungsart" MinWidth="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource ResourceKey=viewModel}, Path=Leistungsarten}"
DisplayMemberPath="Bezeichnung"
SelectedValue="{Binding Path=BDELeistungsartID, Mode=OneWay, Converter={StaticResource ResourceKey=NullableInt2IntConverter}}"
SelectedValuePath="BDELeistungsartID"
IsEnabled="false"
IsEditable="False"
Height="35">
</ComboBox>
</DataTemplate>
答案 0 :(得分:1)
您可以使用ComboBox,但覆盖Template属性以仅显示Label。您还必须重新创建Click事件。
最简单的方法是使用像Snoop或Blend这样的工具,看看默认的ComboBox模板是什么样子,并将其修改为你想要的。
答案 1 :(得分:1)
非常感谢您的回答。是的,使用Template属性为我工作:
<ComboBox ItemsSource="{Binding Source={StaticResource ResourceKey=viewModel}, Path=Leistungsarten}"
DisplayMemberPath="Bezeichnung"
SelectedValue="{Binding Path=BDELeistungsartID, Mode=OneWay, Converter={StaticResource ResourceKey=NullableInt2IntConverter}}"
SelectedValuePath="BDELeistungsartID">
<ComboBox.Template>
<ControlTemplate>
<Label Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.Bezeichnung}"
Margin="0,0,0,0" Padding="0,0,0,0"/>
</ControlTemplate>
</ComboBox.Template>
</ComboBox>