I have a GridView
<GridView ItemsSource="{x:Bind ViewModel.SoundEffects}">
<GridView.ItemTemplate>
<DataTemplate x:dataType="?">
<Button Style="{StaticResource defaultButton}"
Content="{Binding Name}"
Tag="{Binding FileName}"
Command="{x:Bind ViewModel.PlayCommand}"
CommandParameter="{Binding FileName}"/>
</DataTemplate>
</GridView.ItemTemplate>
Whenever I try to compile it, it says I need to specify a model, but I can't figure out, how to make model, which contains definition for ViewModel, when I tried to create an interface:
public interface ISoundEffectButton
{
string Name { get; }
string FileName { get; }
ViewModels.MainPageViewModel ViewModel { get; }
}
But this didn't work and crashed the whole debugger.
Thanks for your time.
So first, you need to make you model like this:
It is a
Class, not a interface. Then use it in your page like this:The
x:DataTypeofGridViewcan be set as following:In your ViewModel, you can use a collection for your data:
At last, use your ViewModel in the cs file of your page:
The
GridViewshould be like this:I wrote a demo here for your problem, you may have a look.