组合框与项目模板中的按钮

时间:2011-01-26 07:58:15

标签: wpf combobox datatemplate

我想在组合框ItemTemplate中添加一个按钮,允许用户点击它并删除点击的项目。

这是我到目前为止所做的:

<dxe:ComboBoxEdit Name="cboUserCustomReports"
                      Width="300" Height="Auto"
                      Margin="0,5,0,5"
                      ItemsSource="{Binding Path=UserReportProfileList,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
                      EditValue="{Binding Path=UserReportProfileID,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                      ValueMember="UserReportProfileID"
                      DisplayMember="ReportName"
                      PopupClosed="cboUserCustomReports_PopupClosed">
            <dxe:ComboBoxEdit.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="23"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="{Binding XPath=ReportName}" 
                                   VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                        <Button Grid.Column="1"
                                Width="23" Height="23"
                                VerticalAlignment="Center" HorizontalAlignment="Right">
                            <Button.Template>
                                <ControlTemplate>
                                    <Image Source="/RMSCommon;component/Resources/Delete.ico"></Image>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </Grid>
                </DataTemplate>
            </dxe:ComboBoxEdit.ItemTemplate>
        </dxe:ComboBoxEdit>

我的问题是我的显示成员没有显示在TextBlock中,只显示了按钮模板的图像。

这是一张它的样子:

ComboBox

我如何解决我的问题?

由于

1 个答案:

答案 0 :(得分:2)

如果已定义DataTemplate,则DisplayMember将不起作用。但是我看到你有一个带有XPath绑定到 ReportName 的TextBlock。这应该可以解决问题。检查这个绑定,我认为存在错误。检查Visual Studio输出窗口是否存在绑定错误。

<TextBlock Grid.Column="0" 
           Text="{Binding XPath=ReportName}"
           VerticalAlignment="Stretch" HorizontalAlignment

您是否真的需要XPath绑定?如果您不确定,请尝试将Text="{Binding XPath=ReportName}"替换为Text="{Binding ReportName}"。也许这是唯一的问题。

相关问题