<tfoot id='iGPXL'></tfoot>

      <small id='iGPXL'></small><noframes id='iGPXL'>

      • <bdo id='iGPXL'></bdo><ul id='iGPXL'></ul>
    1. <i id='iGPXL'><tr id='iGPXL'><dt id='iGPXL'><q id='iGPXL'><span id='iGPXL'><b id='iGPXL'><form id='iGPXL'><ins id='iGPXL'></ins><ul id='iGPXL'></ul><sub id='iGPXL'></sub></form><legend id='iGPXL'></legend><bdo id='iGPXL'><pre id='iGPXL'><center id='iGPXL'></center></pre></bdo></b><th id='iGPXL'></th></span></q></dt></tr></i><div id='iGPXL'><tfoot id='iGPXL'></tfoot><dl id='iGPXL'><fieldset id='iGPXL'></fieldset></dl></div>
      <legend id='iGPXL'><style id='iGPXL'><dir id='iGPXL'><q id='iGPXL'></q></dir></style></legend>
    2. c# wpf - 不能同时设置 DisplayMemberPath 和 ItemTemplate

      时间:2023-10-08
        <tbody id='3Bpge'></tbody>

      <tfoot id='3Bpge'></tfoot>
        1. <small id='3Bpge'></small><noframes id='3Bpge'>

          <i id='3Bpge'><tr id='3Bpge'><dt id='3Bpge'><q id='3Bpge'><span id='3Bpge'><b id='3Bpge'><form id='3Bpge'><ins id='3Bpge'></ins><ul id='3Bpge'></ul><sub id='3Bpge'></sub></form><legend id='3Bpge'></legend><bdo id='3Bpge'><pre id='3Bpge'><center id='3Bpge'></center></pre></bdo></b><th id='3Bpge'></th></span></q></dt></tr></i><div id='3Bpge'><tfoot id='3Bpge'></tfoot><dl id='3Bpge'><fieldset id='3Bpge'></fieldset></dl></div>

            <legend id='3Bpge'><style id='3Bpge'><dir id='3Bpge'><q id='3Bpge'></q></dir></style></legend>

              <bdo id='3Bpge'></bdo><ul id='3Bpge'></ul>

              • 本文介绍了c# wpf - 不能同时设置 DisplayMemberPath 和 ItemTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 listboxItem 中添加工具提示,但是当有 DisplayMemberPath 时它开始出现问题.错误信息说:不能同时设置 DisplayMemberPath 和 ItemTemplate.当我删除 DisplayMemberPath 时,每个列表项中的工具提示都在工作.但我不想删除 DisplayMemember,因为我需要它.如何解决这个问题?

                I want to add tooltip in listboxItem but it starts problem when there is DisplayMemberPath. Error message said: cannot set both DisplayMemberPath and ItemTemplate. When I removed DisplayMemberPath, tooltip in each list item is working. But i dont want to remove DisplayMemember because i need it. How to solve this problem?

                               <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}"  ItemsSource="{Binding Strings}" DisplayMemberPath="Toys" MouseDoubleClick="lstToys_MouseDoubleClick">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding}" ToolTip="Here is a tooltip"/>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                

                推荐答案

                DisplayMemberPath 实际上是单个属性的模板,显示在 TextBlock 中.如果你设置:

                DisplayMemberPath is, in effect, a template for a single property, shown in a TextBlock. If you set:

                <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}"  
                         ItemsSource="{Binding Strings}" DisplayMemberPath="Toys">
                </ListBox>
                

                相当于:

                <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}"  
                         ItemsSource="{Binding Strings}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Toys}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                

                您可以简单地删除 DisplayMemberPath 路径并使用 DataTemplateBinding 中的值:

                You can simply remove the DisplayMemberPath path and use the value in your DataTemplate's Binding:

                <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}"  
                         ItemsSource="{Binding Strings}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Toys}" ToolTip="Here is a tooltip!"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                

                编辑

                如果你想设置一个ToolTip但保留DisplayMemberPath,你可以在ItemContainerStyle处进行:

                If you want to set a ToolTip but keep the DisplayMemberPath, you can do it at the ItemContainerStyle:

                <ListBox x:Name="lstToys" Style="{DynamicResource ListBoxStyle1}"  
                         ItemsSource="{Binding Strings}" DisplayMemberPath="Toys">
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="ToolTip" Value="Here's a tooltip!"/>
                        </Style>
                    </ListBox.ItemContainerStyle>
                </ListBox>
                

                我建议不要这样做.请记住,使用 DisplayMemberPath 会阻止您在数据模板中进行任何复杂的绑定.

                I'd advise against it. Remember that use DisplayMemberPath stops you from any complex binding in your data template.

                这篇关于c# wpf - 不能同时设置 DisplayMemberPath 和 ItemTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何允许用户编辑 ListBox 中的项目? 下一篇:在 C# WinForms 中为 Listbox/ListView 行的部分着色的方法?

                相关文章

                  1. <legend id='oAJAX'><style id='oAJAX'><dir id='oAJAX'><q id='oAJAX'></q></dir></style></legend>
                  2. <tfoot id='oAJAX'></tfoot>

                  3. <i id='oAJAX'><tr id='oAJAX'><dt id='oAJAX'><q id='oAJAX'><span id='oAJAX'><b id='oAJAX'><form id='oAJAX'><ins id='oAJAX'></ins><ul id='oAJAX'></ul><sub id='oAJAX'></sub></form><legend id='oAJAX'></legend><bdo id='oAJAX'><pre id='oAJAX'><center id='oAJAX'></center></pre></bdo></b><th id='oAJAX'></th></span></q></dt></tr></i><div id='oAJAX'><tfoot id='oAJAX'></tfoot><dl id='oAJAX'><fieldset id='oAJAX'></fieldset></dl></div>
                  4. <small id='oAJAX'></small><noframes id='oAJAX'>

                      <bdo id='oAJAX'></bdo><ul id='oAJAX'></ul>