Skip to content

Instantly share code, notes, and snippets.

@codebeaulieu
Created February 25, 2018 16:10
Show Gist options
  • Save codebeaulieu/ae45a07f17fdad6fb7fce9c70a4b0bbc to your computer and use it in GitHub Desktop.
Save codebeaulieu/ae45a07f17fdad6fb7fce9c70a4b0bbc to your computer and use it in GitHub Desktop.
ui dashboard
public class Dashboard : ContentPageBase<ViewModels.Dashboard>
{
Grid _mainLayout;
// 1
Image _images;
Label _status;
// 2
public Dashboard()
{
ViewModel = new ViewModels.Dashboard();
ViewModel?.InitializeCommand.Execute();
}
// 3
protected override void SetupUserInterface()
{
this.BackgroundColor = Color.FromHex("#333333");
NavigationPage.SetBackButtonTitle(this, "Back");
_mainLayout = new Grid
{
BackgroundColor = Color.Transparent,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(16, 24, 16, 8),
ColumnDefinitions = new ColumnDefinitionCollection {
new ColumnDefinition { Width = GridLength.Star },
},
RowDefinitions = new RowDefinitionCollection {
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(3, GridUnitType.Star) },
}
};
_status = new Label
{
FontSize = 22,
FontFamily = "AvenirNext-Medium",
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.EndAndExpand,
TextColor = Color.White
};
_images = new Image
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.StartAndExpand,
Aspect = Aspect.AspectFit,
HeightRequest = 350
};
_mainLayout.Children.Add(_status, 0, 0);
_mainLayout.Children.Add(_images, 0, 1);
Content = _mainLayout;
}
// 4
protected override void BindControls()
{
this.OneWayBind(ViewModel, vm => vm.Title, c => c.Title)
.DisposeWith(ControlBindings);
this.Bind(ViewModel, x => x.StatusMessage, c => c._status.Text)
.DisposeWith(ControlBindings);
this.WhenAnyValue(x => x.ViewModel.CurrentImage)
.Where(fileName => !string.IsNullOrEmpty(fileName))
.SubscribeOn(RxApp.TaskpoolScheduler)
.Select(fileName => ImageSource.FromFile(fileName))
.ObserveOn(RxApp.MainThreadScheduler)
.BindTo(this, x => x._images.Source)
.DisposeWith(ControlBindings);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment