On a Mainpage XAML I have a CommandBar that I use to display the application main buttons and a message area. It looks a bit like this:
<CommandBar x:Name="topcmdbar" Grid.Column="0 " Grid.ColumnSpan="3"
IsDynamicOverflowEnabled="False" ClosedDisplayMode="Compact"
VerticalAlignment="Top" Opacity=".5"
Background="Transparent" Visibility="Visible"
>
<CommandBar.Content>
<Grid >
<TextBlock x:Name="TopCmdBarContent" x:FieldModifier="public" HorizontalAlignment="Left" Margin="10,5,0,0" VerticalAlignment="Stretch"/>
</Grid>
</CommandBar.Content>
<AppBarButton FontFamily="Segoe MDL2 Assets" Content="" FontSize="18" Label="Open Folder" Tapped="StartNewPlaylist" HorizontalAlignment="Left"/>
<AppBarButton etc etc etc........
I have a class that, amongst other things, loads the files for the application. I'd like to display from that class the progress of the loading on the TopCmdBarContent.
I've tried various strategies for this, for e.g. passing the MainPage as an argument to the method that initializes the class, but I cannot access it. I've even thought of creating from within the class its own "progress" message,but then I'd need to access the grid from the mainpage to hang it to....
So, for example, I need to have a method that does something like this within the class:
public async void InitializePlayList()
{
int countfiles=0;
StorageFolder f = await GetSelectedFolderAsync();
foreach (var file in f)
{
Do_a_bunch_of_stuff(f);
countfiles+=1;
TopCmdBarContent="Hang in there, "countfiles.ToString()+" processed";
}
I have been trying this potential solution but I keep getting this error: "The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E)"
Any idea how I can do this?