English 中文(简体)
Can t 让 ToString()利用C++为ComboBoxItem的IIspectable含量工作
原标题:Can t get ToString() to work for IInspectable content of ComboBoxItem for WinUI 3 using C++

在为ComboBoxItem提供一台显像仪时,你假定能够利用托String(TString)功能提供显示器。 但这一功能从未被叫到,显示只是一个空白箱。

习俗二者:

class ComboboxItem : public winrt::implements<ComboboxItem, winrt::Windows::Foundation::IInspectable>
{
public:
    ComboboxItem() : m_text(L"Hello") {}

    hstring Text() { return m_text; }
    void Text(hstring const& value) { m_text = value; }

    winrt::Windows::Foundation::IInspectable Value() { return m_value; }
    void Value(winrt::Windows::Foundation::IInspectable const& value) { m_value = value; }

    hstring ToString() cons { return m_text; }    // This is never called

private:
    hstring m_text;
    winrt::Windows::Foundation::IInspectable m_value;
};

Adding to ComboBox:

comboxBox.Items().Append(winrt::make<ComboboxItem>());

失踪的“特别引诱”在ComboBox展示什么?

问题回答

我在C#中执行,是因为 这是我能够开展工作的唯一途径。

using Microsoft.UI.Xaml.Controls;

namespace App2CSharp
{
    internal class MyComboBoxItem : ComboBoxItem
    {
        public MyComboBoxItem()
        {
            Content = "TEST";
        }
    }
}

XAML:

<ComboBox x:Name="MyComboBox" Header="Colors" PlaceholderText="Pick a color" Width="200">
            <x:String>Blue</x:String>
            <x:String>Green</x:String>
            <x:String>Red</x:String>
            <x:String>Yellow</x:String>
            <ComboBoxItem>Gray</ComboBoxItem>
        </ComboBox>

而且

ComboBoxItem c = new MyComboBoxItem();
MyComboBox.Items.Add(c);

“entergraph





相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签