自动完成框是邪恶的

发布于 2025-01-08 07:09:31 字数 3036 浏览 0 评论 0原文

问题如下:

为什么 AutoCompleteBox 讨厌我?我花了至少 3 天的时间尝试让 ACB 在下拉列表中显示数据。我得到的只是下拉列表中的类名称。列表框工作完美。

感谢您的时间和精力!

这是它正在做什么的图片: image

现在这是列表框的 XAML

    <ListBox Height="100" HorizontalAlignment="Left" Margin="367,81,0,0" Name="ListBox1" VerticalAlignment="Top" Width="184" ItemsSource="{Binding}" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Together}" />
                    <TextBlock Text=" sadssa" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

这是自动完成框的 XAML

<sdk:AutoCompleteBox x:Name="atcTextBox" ItemsSource="{Binding}" ValueMemberPath="CountryNumber" FilterMode="StartsWith"
            IsTextCompletionEnabled="True" Height="30" MinimumPopulateDelay="0" MinimumPrefixLength="0" Margin="29,225,259,225">
            <sdk:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=CountryName}" />
                        <TextBlock Text="{Binding Path=Together}" />
                    </StackPanel>
                </DataTemplate>
            </sdk:AutoCompleteBox.ItemTemplate>
        </sdk:AutoCompleteBox>

和隐藏代码。

Partial Public Class pgMain
    Inherits Page

    Public Sub New()
        InitializeComponent()

        Dim a = GetCountry()
        ListBox1.ItemsSource = a
        atcTextBox.ItemsSource = a
    End Sub

    Private Function GetCountry() As List(Of Country)
        Dim lstCountry As New List(Of Country)()
        lstCountry.Add(New Country() With {.CountryName = "India"})
        lstCountry.Add(New Country() With {.CountryName = "USA"})
        lstCountry.Add(New Country() With {.CountryName = "Australia"})
        lstCountry.Add(New Country() With {.CountryName = "Germany"})
        lstCountry.Add(New Country() With {.CountryName = "England"})
        Return lstCountry
    End Function

End Class

Public Class Country
    Private m_CountryName As String
    Public Property CountryName() As String
        Get
            Return m_CountryName
        End Get
        Set(ByVal value As String)
            m_CountryName = value
        End Set
    End Property

    Private m_CountryNumber As Integer

    Public Property CountryNumber As Integer
        Get
            Return m_CountryNumber
        End Get
        Set(value As Integer)
        End Set
    End Property

    Public ReadOnly Property Together
        Get
            Return m_CountryName & " " & m_CountryNumber.ToString
        End Get
    End Property

    Public Sub New()
        m_CountryNumber = Rnd(Timer) * 100
    End Sub
End Class

Heres the Question:

Why does the AutoCompleteBox hate me?? I've spent at least 3 days trying to get the ACB to display data in the drop down list. All I get is the Class name in the Dropdown list. THe Listbox work Perfectly.

Thank you for your Time and Effort!

Heres a Pic of whats its doing:
image

Now heres the XAML for the Listbox

    <ListBox Height="100" HorizontalAlignment="Left" Margin="367,81,0,0" Name="ListBox1" VerticalAlignment="Top" Width="184" ItemsSource="{Binding}" >
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Together}" />
                    <TextBlock Text=" sadssa" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

Here's the XAML for the AutoCompleteBox

<sdk:AutoCompleteBox x:Name="atcTextBox" ItemsSource="{Binding}" ValueMemberPath="CountryNumber" FilterMode="StartsWith"
            IsTextCompletionEnabled="True" Height="30" MinimumPopulateDelay="0" MinimumPrefixLength="0" Margin="29,225,259,225">
            <sdk:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=CountryName}" />
                        <TextBlock Text="{Binding Path=Together}" />
                    </StackPanel>
                </DataTemplate>
            </sdk:AutoCompleteBox.ItemTemplate>
        </sdk:AutoCompleteBox>

And The Code Behide.

Partial Public Class pgMain
    Inherits Page

    Public Sub New()
        InitializeComponent()

        Dim a = GetCountry()
        ListBox1.ItemsSource = a
        atcTextBox.ItemsSource = a
    End Sub

    Private Function GetCountry() As List(Of Country)
        Dim lstCountry As New List(Of Country)()
        lstCountry.Add(New Country() With {.CountryName = "India"})
        lstCountry.Add(New Country() With {.CountryName = "USA"})
        lstCountry.Add(New Country() With {.CountryName = "Australia"})
        lstCountry.Add(New Country() With {.CountryName = "Germany"})
        lstCountry.Add(New Country() With {.CountryName = "England"})
        Return lstCountry
    End Function

End Class

Public Class Country
    Private m_CountryName As String
    Public Property CountryName() As String
        Get
            Return m_CountryName
        End Get
        Set(ByVal value As String)
            m_CountryName = value
        End Set
    End Property

    Private m_CountryNumber As Integer

    Public Property CountryNumber As Integer
        Get
            Return m_CountryNumber
        End Get
        Set(value As Integer)
        End Set
    End Property

    Public ReadOnly Property Together
        Get
            Return m_CountryName & " " & m_CountryNumber.ToString
        End Get
    End Property

    Public Sub New()
        m_CountryNumber = Rnd(Timer) * 100
    End Sub
End Class

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

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

发布评论

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

评论(1

安人多梦 2025-01-15 07:09:31

找到了答案。

主题化导致自动完成框中出现错误。我删除了主题,自动完成框现在可以工作了。

    <toolkit:Theme ThemeUri="/System.Windows.Controls.Theming.BureauBlue;component/Theme.xaml">
    </toolkit:Theme>

现在看看是否有解决办法..

Found the Answer.

Themeing was causeing an error in the AutocompleteBox. I removed the theme and the Autocomplete box is working now.

    <toolkit:Theme ThemeUri="/System.Windows.Controls.Theming.BureauBlue;component/Theme.xaml">
    </toolkit:Theme>

Now to see if there is a fix for that..

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