-
- mandalorianbob
- Posts: 9
- Joined:
Image Binding to Texture Source
I also wasn't able to get Image binding to work to a TextureSource.
The code to assign the view model
And the View Model itself
Nothing shows up except "Other Games", which is the value of OtherGamesTitle.
No binding errors, no exceptions. Verified that the OtherGames ienumerable has 2 objects in it, which both have TextureSources in them.
Code: Select all
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding OtherGamesTitle}" />
<ItemsControl ItemsSource="{Binding OtherGames}" Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="1" Text="{Binding Name}" />
<Image Source="{Binding Thumbnail}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
Code: Select all
private async void Start()
{
if (DataObject is MainViewModel mainViewModel)
{
await mainViewModel.OnNavigatedToAsync();
}
View.Content.DataContext = DataObject;
}
Code: Select all
public class MainViewModel : ScriptableObject
{
[SerializeField]
private OtherGameData[] other_games;
public IEnumerable<IOtherGameData> OtherGames { get; private set; }
public string OtherGamesTitle => "Other Games";
public Task OnNavigatedToAsync()
{
if (OtherGames == null)
{
OtherGames = other_games.Select(ogd =>
{
return new OtherGamePresenter() { Name = ogd.Name, Thumbnail = new TextureSource(ogd.Thumbnail) };
});
}
return Task.CompletedTask;
}
class OtherGamePresenter : IOtherGameData
{
public string Name { get; set; }
public ImageSource Thumbnail { get; set; }
}
}
No binding errors, no exceptions. Verified that the OtherGames ienumerable has 2 objects in it, which both have TextureSources in them.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Image Binding to Texture Source
Hi,
In Noesis the ItemsSource only works when you expose a property that implements the IList interface, could you try to that?
Although I verified that we are not showing any error when you bind any other type, we'll fix it for the next version.
Please let me know if you have any other problem.
In Noesis the ItemsSource only works when you expose a property that implements the IList interface, could you try to that?
Although I verified that we are not showing any error when you bind any other type, we'll fix it for the next version.
Please let me know if you have any other problem.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Image Binding to Texture Source
Just an addition... from the point of view of Noesis using an IEnumerable won't be efficient because we access items using index in many cases.
And in the code you attached would be even worse, because everytime the collection is iterated it will create new objects.
And in the code you attached would be even worse, because everytime the collection is iterated it will create new objects.
-
- mandalorianbob
- Posts: 9
- Joined:
Re: Image Binding to Texture Source
You're right that the IEnumerable, especially with the Linq query in it, wouldn't be efficient.
That said, you guys very explicitly put in your docs that this is supposed to mimic WPF, and any deviation should be considered a bug. IEnumerable is kind of the foundational collective type in XAML. It's a pretty severe breaking change to require IList ... anywhere, really, but especially in ItemsControl which is the most basic form of repeater control.
So ... just throwing that out there. That's a much bigger break than it sounds. For instance, now in order to use an ItemsControl - the most basic form of repeater - the requirements have gone from
(which is obviously flexible enough to allow for custom IEnumerators to be used)
to requiring
That seems like a lot.
I guess I would encourage you to be very explicit about that both in the documentation and yeah, with a very robust error message.
That said, you guys very explicitly put in your docs that this is supposed to mimic WPF, and any deviation should be considered a bug. IEnumerable is kind of the foundational collective type in XAML. It's a pretty severe breaking change to require IList ... anywhere, really, but especially in ItemsControl which is the most basic form of repeater control.
So ... just throwing that out there. That's a much bigger break than it sounds. For instance, now in order to use an ItemsControl - the most basic form of repeater - the requirements have gone from
Code: Select all
IEnumerator GetEnumerator();
to requiring
Code: Select all
IEnumerator GetEnumerator();
int Count { get; }
bool IsSynchronized { get; }
object SyncRoot { get;
void CopyTo(Array array, int index);
object this[int index] { get; set; }
bool IsFixedSize { get; }
bool IsReadOnly { get; }
int Add(object value);
void Clear();
bool Contains(object value);
int IndexOf(object value);
void Insert(int index, object value);
void Remove(object value);
void RemoveAt(int index);
I guess I would encourage you to be very explicit about that both in the documentation and yeah, with a very robust error message.
-
- mandalorianbob
- Posts: 9
- Joined:
Re: Image Binding to Texture Source
Just realized I forgot to add that yes, IList did work.
Re: Image Binding to Texture Source
In this case, you don't need to implement IList at all, because we support C# arrays. So casting to IOtherGameData[] in your example should do the trick.
It is true, that any deviation from WPF is considered a bug by our team but this is a special situation because only implementing IEnumerable can lead to inefficiencies like:
WPF, supports it, hiding the inefficiency and we think this is dangerous. But yeah, we could open a ticket to support this if you think this is critical. We will emit a warning in these scenarios, so at the end, we are not sure if it makes sense giving support for this pattern. :)
It is true, that any deviation from WPF is considered a bug by our team but this is a special situation because only implementing IEnumerable can lead to inefficiencies like:
- When using with INotifyCollectionChanged, based on indices
- ItemsControl and virtualization also need to access the collection by index
WPF, supports it, hiding the inefficiency and we think this is dangerous. But yeah, we could open a ticket to support this if you think this is critical. We will emit a warning in these scenarios, so at the end, we are not sure if it makes sense giving support for this pattern. :)
-
- mandalorianbob
- Posts: 9
- Joined:
Re: Image Binding to Texture Source
I mean it's totally fair - WPF was not very efficient haha. I've just done a lot of XAML development, so I'm trying to reconcile what I expect from XAML vs what's required for game performance. That's why I wasn't even suggesting a change really, just documentation and messaging.
I'm prototyping some stuff while I evaluate NoesisGUI, so I'm trying to figure out the pitfalls so I can evaluate properly.
But thinking about it - is this true of all of your data controls then? Does Noesis just generally not support IEnumerable?
I'm prototyping some stuff while I evaluate NoesisGUI, so I'm trying to figure out the pitfalls so I can evaluate properly.
But thinking about it - is this true of all of your data controls then? Does Noesis just generally not support IEnumerable?
Who is online
Users browsing this forum: No registered users and 7 guests