项目模板中带有按钮的组合框

发布于 2024-10-14 07:39:19 字数 2103 浏览 3 评论 0原文

我想向组合框 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>

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

下面是它的外观图片:

ComboBox

我该如何解决我的问题?

谢谢

I would like to add a button to the combobox ItemTemplate, that allows the user to click it and remove the clicked item.

This is what i have so far:

<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>

My problem is that my Displaymember is not showing in the TextBlock and only the image of the button template is showing.

Here is a picture of what it looks like:

ComboBox

How do i solve my problem?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2024-10-21 07:39:19

如果您定义了 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}"。也许这是唯一的问题。

DisplayMember will not work if you have defined a DataTemplate. However I have seen that you have a TextBlock with a XPath-binding to ReportName. This should do the trick. Check this binding, I assume that there in is the mistake. Check the Visual Studio output-window for binding errors.

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

Are you shure that you need an XPath-binding? If you're not sure, try to replace Text="{Binding XPath=ReportName}" through Text="{Binding ReportName}". Maybe this is the only problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文