Skip to content

Instantly share code, notes, and snippets.

View damirarh's full-sized avatar

Damir Arh damirarh

View GitHub Profile
public class IncrementalLoadingBehavior : Behavior<LongListSelector>
{
public ICommand LoadCommand { get; set; }
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.ItemRealized += OnItemRealized;
}
<i:Interaction.Behaviors>
<b:IncrementalLoadingBehavior LoadCommand="{Binding LoadCommand}" />
</i:Interaction.Behaviors>
<phone:LongListSelector cal:Message.Attach="[Event ItemRealized]=[Action LoadMoreItems($eventArgs)]" />
public class IncrementalLoadingTrigger : TriggerBase<LongListSelector>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.ItemRealized += OnItemRealized;
}
private void OnItemRealized(object sender, ItemRealizationEventArgs e)
{
<i:Interaction.Triggers>
<t:IncrementalLoadingTrigger>
<cal:ActionMessage MethodName="LoadMoreItems"/>
</t:IncrementalLoadingTrigger>
</i:Interaction.Triggers>
public ViewModel()
{
Init();
}
private async void Init()
{
var file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Text.txt");
Text = await FileIO.ReadTextAsync(file);
}
public class BooleanToVisibilityConverter : IValueConverter
{
public bool Inverted { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
if (!(value is bool))
{
return Visibility.Collapsed;
}
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ProgressBar Value="{Binding Progress}"
Minimum="0"
Maximum="1"
Visibility="{Binding Initialized, Converter={StaticResource InvertedBoolToVisibilityConverter}}"/>
<TextBlock Text="{Binding Text}"
TextWrapping="Wrap"
Visibility="{Binding Initialized, Converter={StaticResource BoolToVisibilityConverter}}"
Style="{StaticResource BasicTextStyle}" />
</Grid>
private readonly Task _initializingTask;
public ViewModel()
{
_initializingTask = Init();
}
private async Task Init()
{
var file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Text.txt");
var file = await Package.Current.InstalledLocation.GetFileAsync(@"\Assets\Text.txt");
file.CopyAsync(ApplicationData.Current.LocalFolder);