I cannot get data binding to work on WinUI 3 ListView any more.

Mike Conley 0 Reputation points
2023-11-21T20:41:37.3933333+00:00

Yesterday after noon I had this really nice ListView of all the Segoe Fluent Icons. That was a great feat in it's self since the FontIcon cannot bind the text to a Text Glyph code. But once figured out is was great. Woked for quiet a while binding nicely...

A few hours later, not touching anything around the control and it will no longer update the data binding. After awhile of pounding my head I started a new Template Studio Navigation solution and from the ground up built the stuff to load the icons.... and again it doesn't work.

I've checked the bindings are correct. Even the Mode=Oneway. The source of the data is a property that is listed as [ObservableProperty] on the data model and the property hold it. I also tried the InotifiyPropertyChange route. The bindings are all correct. I have even stepped through enough to see that the datascontext has changed. In fact, I can see that it holds all 1403 items in it's datacontext. But checking the items in it's list shows 0.

I have no clue what changed or how. If anyone sees something wrong, please let me know. Again I see the data gets into the DataContext, it's just not doing anything with it.

My data is simple and loaded from a asset json. file.

using CommunityToolkit.Mvvm.ComponentModel;
using WorldClock.Contracts.Models;

namespace WorldClock.Models;
[ObservableObject]
public partial class FontIconModel : IFontIconModel
{
    [ObservableProperty]
    private string _HexCode;

    [ObservableProperty]
    private string _Name;

    [ObservableProperty]
    private char _FontCode;

}

The Xaml is simple It doesn't work with the bind or setting the datacontext in code. The data is a List<FontIconModle.

   <Grid x:Name="ContentArea">

       <ListView x:Name="lvIcons" Width="310" Height="500" DataContext="{x:Bind ViewModel.FontIconData, Mode=OneWay}" Background="Beige" >
           <ListView.ItemTemplate>
               <DataTemplate x:Name="dtIconList" x:DataType="md:FontIconModel">
                   <Grid Width="310" HorizontalAlignment="Stretch">
                       <Grid.ColumnDefinitions>
                           <ColumnDefinition Width="50"/>
                           <ColumnDefinition Width="310"/>
                       </Grid.ColumnDefinitions>
                       <FontIcon Grid.Column="0" Glyph="{x:Bind FontCode, Mode=OneWay}" Width="50"/>
                       <TextBlock Grid.Column="1" Text="{x:Bind Name, Mode=OneWay}" Width="310" />
                   </Grid>
               </DataTemplate>
            </ListView.ItemTemplate>
       </ListView>
       
   </Grid>
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,904 questions
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
791 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.