0

So I am currently trying to create a list view for a bunch of sounds. I made a new file and added a "SoundListItem" class, as the datatype in another file. I cannot get XAML to accept it at all. (yes the SoundListMgr.hpp file is included inside the Page's header)

SoundListMgr.hpp

...

#define STR_BFALSE  "False"
#define STR_BTRUE   "True"

#define CLANK_LISTICON_FROMFILE ""
#define CLANK_LISTICON_FROMNET  ""
#define CLANK_LISTICON_ERROR    ""

...

WINRT_EXPORT namespace SoundListMgr // I tried to do everything here from adding the namespace to the class, to this. Nothing works.
{
    class SoundListItem
    {
        std::string soundName;
        std::string soundLocation;
        std::string soundKeybind;
        std::string soundLocationIcon;
        std::string soundIconTooltip;
        std::string progressRingEnabled;
        std::string keybindBtnForecolor;

        SoundListItem(
            std::string SoundName,
            std::string SoundLocation,
            std::string SoundKeybind,
            std::string SoundLocationIcon,
            std::string SoundIconTooltip = "",
            std::string ProgressRingEnabled = STR_BFALSE,
            std::string KeybindBtnForecolor = "#6d6d6d")
        {
            soundName = SoundName;
            soundLocation = SoundLocation;
            soundKeybind = SoundKeybind;
            soundLocationIcon = SoundLocationIcon;
            soundIconTooltip = SoundIconTooltip;
            progressRingEnabled = ProgressRingEnabled;
            keybindBtnForecolor = KeybindBtnForecolor;
        }
    };
}

[Page].xaml

...

<Page.Resources>
        
        <DataTemplate x:Key="SoundListViewTemplate" x:DataType="??????">
            <Grid>
                <FontIcon Glyph="{x:Bind SoundLocationIcon}" HorizontalAlignment="Left" ToolTipService.ToolTip="{x:Bind SoundIconTooltip}"/>
                <ProgressRing IsActive="{x:Bind ProgressRingEnabled}" HorizontalAlignment="Left" VerticalAlignment="Center" Width="20" Height="20"/>
                <StackPanel Margin="20 0, 50, 0">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock
                            Text="{x:Bind SoundName}"
                            Style="{ThemeResource BodyStrongTextBlockStyle}"
                            Margin="12,6,0,0"/>
                    </StackPanel>
                    <TextBlock 
                            Grid.Row="1"
                            Text="{x:Bind SoundLocation}"
                            Style="{ThemeResource CaptionTextBlockStyle}"
                            TextWrapping="NoWrap"
                            Margin="12,0,70,8"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <HyperlinkButton Margin="0, 0, 5, 0" Content="{x:Bind SoundKeybind}" Foreground="{x:Bind KeybindBtnForecolor}"/>
                    <Button Foreground="Lime" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <FontIcon Glyph="&#xF5B0;" />
                    </Button>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

xmlns:local is defined as using:[AppName]. I am using the C++ Winui 3 project in Visual Studio 2022.

Davide_24
  • 67
  • 7
  • 2
    Your `SoundListtem` must be a bindable type. XAML doesn't know how to bind to raw C++ classes. Declare it in your IDL file as `[Windows.UI.Xaml.Data.Bindable] runtimeclass SoundListItem { ... }` and then implement it as a C++/WinRT implementation class. – Raymond Chen Mar 21 '23 at 22:47

0 Answers0