using SettingWallpaper.Models;
using SettingWallpaper.Views;
using SettingWallpaper.ViewModels;
+using System.Windows.Input;
+using System.Collections;
namespace SettingWallpaper.Core
{
+ static class WallpaperViewBindings
+ {
+ public static BindingProperty<WallpaperView, IEnumerable> WallpaperListProperty { get; } = new BindingProperty<WallpaperView, IEnumerable>
+ {
+ Setter = (v, value) => v.WallpaperList = value,
+ };
+ }
+
+ static class CollectionViewBindings
+ {
+ public static BindingProperty<CollectionView, ICommand> SelectionChangedCommandProperty { get; } = new BindingProperty<CollectionView, ICommand>
+ {
+ Setter = (v, value) => v.SelectionChangedCommand = value,
+ };
+ }
+
class ViewManager : IDisposable
{
private WallpaperView wallpaperView;
wallpaperViewModel.WallpaperChanged += OnWallpaperChanged;
wallpaperView = new WallpaperView();
+
+ var session = new BindingSession<WallpaperViewModel>();
+ wallpaperView.BindingContextChanged += (sender, e) =>
+ {
+ if (wallpaperView.BindingContext is WallpaperViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ wallpaperView.SetBinding(session, WallpaperViewBindings.WallpaperListProperty, "WallpaperListSource");
wallpaperView.BindingContext = wallpaperViewModel;
- wallpaperView.SetBinding(WallpaperView.WallpaperListProperty, "WallpaperListSource");
+
wallpaperView.TouchEvent += (object source, View.TouchEventArgs e) =>
{
if (e.Touch.GetState(0) == PointStateType.Down)
{
if (albumView == null)
{
+ var session = new BindingSession<AlbumViewModel>();
+
albumView = new AlbumView(customWindow);
+
+ albumView.BindingContextChanged += (sender, e) =>
+ {
+ if (albumView.BindingContext is AlbumViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+
+ albumView.SetBinding(session, CollectionViewBindings.SelectionChangedCommandProperty, "SelectionChangedCommand");
albumView.BindingContext = albumViewModel;
albumViewModel.AlbumSelected += OnAlbumSelected;
- albumView.SetBinding(CollectionView.SelectionChangedCommandProperty, "SelectionChangedCommand");
}
return albumView;
}
{
if (albumDetailView == null)
{
+ var session = new BindingSession<AlbumDetailViewModel>();
+
albumDetailView = new AlbumDetailView(customWindow);
- albumDetailView.SetBinding(CollectionView.SelectionChangedCommandProperty, "SelectionChangedCommand");
+
+ albumDetailView.BindingContextChanged += (sender, e) =>
+ {
+ if (albumDetailView.BindingContext is AlbumDetailViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ albumDetailView.SetBinding(session, CollectionViewBindings.SelectionChangedCommandProperty, "SelectionChangedCommand");
+
}
albumDetailView.BindingContext = albumDetailViewModel;
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SettingCore" Version="2.0.0" />
- <PackageReference Include="Tizen.NET" Version="12.0.0.18518" />
+ <PackageReference Include="Tizen.NET.API13" Version="13.0.0.18710" />
</ItemGroup>
<ItemGroup>
using Tizen.NUI.Binding;
using Tizen.NUI.Components;
using SettingWallpaper.Common;
+using SettingWallpaper.ViewModels;
+using System.Collections;
namespace SettingWallpaper.Views
{
+ static class RecyclerViewBindings
+ {
+ public static BindingProperty<RecyclerView, IEnumerable> ItemsSourceProperty { get; } = new BindingProperty<RecyclerView, IEnumerable>
+ {
+ Setter = (v, value) => v.ItemsSource = value,
+ };
+ }
class AlbumView : CollectionView
{
private CustomAlbumTitle albumTitleItem;
albumTitleItem = new CustomAlbumTitle();
Header = albumTitleItem;
UpdateItemTemplate();
- this.SetBinding(ItemsSourceProperty, "AlbumListSource");
+
+ var session = new BindingSession<AlbumViewModel>();
+ this.BindingContextChanged += (sender, e) =>
+ {
+ if (this.BindingContext is AlbumViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ this.SetBinding(session, RecyclerViewBindings.ItemsSourceProperty, "AlbumListSource");
}
public void UpdateItemTemplate()
{
ItemTemplate = new DataTemplate(() =>
{
+ var itemSession = new BindingSession<AlbumDetailViewModel>();
+
AlbumItemLayout item = new AlbumItemLayout();
- item.AlbumLabel.SetBinding(TextLabel.TextProperty, "AlbumName");
+
+ item.BindingContextChanged += (sender, e) =>
+ {
+ if (item.BindingContext is AlbumDetailViewModel model)
+ {
+ itemSession.ViewModel = model;
+ }
+ };
+ item.AlbumLabel.SetBinding(itemSession, TextLabelBindings.TextProperty, "AlbumName");
return item;
});
}
using Tizen.NUI.Binding;
using Tizen.NUI.Components;
using SettingWallpaper.Common;
+using SettingWallpaper.ViewModels;
namespace SettingWallpaper.Views
{
{
StyleName = "BackIcon",
};
+
+ var session = new BindingSession<AlbumDetailViewModel>();
+
backButton = new Button()
{
Size2D = AppCommon.buttonSize,
BackgroundColor = Color.Transparent,
};
backButton.Add(icon);
- backButton.SetBinding(Control.CommandProperty, "BackButtonCommand");
+
+ backButton.BindingContextChanged += (sender, e) =>
+ {
+ if (backButton.BindingContext is AlbumDetailViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ backButton.SetBinding(session, ButtonBindings.CommandProperty, "BackButtonCommand");
RelativeLayout.SetVerticalAlignment(backButton, RelativeLayout.Alignment.Center);
+
albumTitle = new TextLabel()
{
StyleName = "ItemText",
HorizontalAlignment = HorizontalAlignment.Begin,
BackgroundColor = Color.Transparent,
};
- albumTitle.SetBinding(TextLabel.TextProperty, "AlbumName");
+
+ albumTitle.BindingContextChanged += (sender, e) =>
+ {
+ if (albumTitle.BindingContext is AlbumDetailViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+
+ albumTitle.SetBinding(session, TextLabelBindings.TextProperty, "AlbumName");
RelativeLayout.SetLeftTarget(albumTitle, backButton);
RelativeLayout.SetLeftRelativeOffset(albumTitle, 1.0f);
RelativeLayout.SetVerticalAlignment(albumTitle, RelativeLayout.Alignment.Center);
protected override View OnCreate()
{
+ NUIApplication.IsUsingXaml = false;
Tizen.Log.Info(Resources.LogTag, "OnCreate");
base.OnCreate();
gadgetResourceManager = NUIGadgetResourceManager;
using SettingWallpaper.LanguageResources;
using SettingCore;
using System.Text;
-
+using System;
+using System.Windows.Input;
+using SettingWallpaper.ViewModels;
+using SettingWallpaper.Models;
+using Tizen.Maps;
namespace SettingWallpaper.Views
{
+ static class ButtonBindings
+ {
+ public static BindingProperty<Button, bool> IsSelectedProperty { get; } = new BindingProperty<Button, bool>
+ {
+ Setter = (v, value) => v.IsSelected = value,
+ };
+
+ public static BindingProperty<Button, ICommand> CommandProperty { get; } = new BindingProperty<Button, ICommand>
+ {
+ Setter = (v, value) => v.Command = value,
+ };
+
+ public static BindingProperty<Button, bool> IsEnabledProperty { get; } = new BindingProperty<Button, bool>
+ {
+ Setter = (v, value) => v.IsEnabled = value,
+ };
+ }
+
+ static class ImageViewBindings
+ {
+ public static BindingProperty<ImageView, string> ResourceUrlProperty { get; } = new BindingProperty<ImageView, string>
+ {
+ Setter = (v, value) => v.ResourceUrl = value,
+ };
+ }
+
+ static class SaveButtonBindings
+ {
+ public static BindingProperty<Button, ICommand> CommandProperty { get; } = new BindingProperty<Button, ICommand>
+ {
+ Setter = (v, value) => v.Command = value,
+ };
+ }
+
class WallpaperView : ImageView
{
private View bottomView;
BackgroundColor = Color.Transparent,
};
previousButton.Add(icon);
- previousButton.SetBinding(IsEnabledProperty, "IsPreviousImageAvailable");
- previousButton.SetBinding(Control.CommandProperty, "PreviousButtonCommand");
+ try
+ {
+ var session = new BindingSession<WallpaperViewModel>();
+
+ previousButton.BindingContextChanged += (sender, e) =>
+ {
+ if (previousButton.BindingContext is WallpaperViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+
+ previousButton.SetBinding(session, ButtonBindings.IsEnabledProperty, "IsPreviousImageAvailable");
+ previousButton.SetBinding(session, ButtonBindings.CommandProperty, "PreviousButtonCommand");
+ }
+ catch (Exception ex)
+ {
+ Tizen.Log.Debug("SRK", "First Vul "+ex.Message);
+ }
+
bottomView.Add(previousButton);
}
};
albumFolder.Add(folderIconNormal);
- albumFolder.SetBinding(Control.CommandProperty, "AlbumFolderCommand");
+
+ var session = new BindingSession<WallpaperViewModel>();
+ albumFolder.BindingContextChanged += (sender, e) =>
+ {
+ if (albumFolder.BindingContext is WallpaperViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ albumFolder.SetBinding(session, ButtonBindings.CommandProperty, "AlbumFolderCommand");
bottomView.Add(albumFolder);
}
wallpaperListView.Add(wallpaper);
Tizen.Log.Info(Resources.LogTag, "Buttons Added");
+ var session = new BindingSession<ImageDataModel>();
+ icon.BindingContextChanged += (sender, e) =>
+ {
+ if (icon.BindingContext is ImageDataModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+
+ icon.SetBinding(session, ImageViewBindings.ResourceUrlProperty, "ThumbnailUrl");
+
+ wallpaper.BindingContextChanged += (sender, e) =>
+ {
+ if (wallpaper.BindingContext is ImageDataModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ wallpaper.SetBinding(session, ButtonBindings.CommandProperty, "WallpaperSelectCommand");
+
wallpaper.BindingContext = item;
- icon.SetBinding(ResourceUrlProperty, "ThumbnailUrl");
- wallpaper.SetBinding(Control.CommandProperty, "WallpaperSelectCommand");
+
}
index++;
}
private void AddNextButton()
{
+ var session = new BindingSession<WallpaperViewModel>();
ImageView icon = new ImageView
{
StyleName = "NextIcon",
BackgroundColor = Color.Transparent,
};
nextButton.Add(icon);
- nextButton.SetBinding(IsEnabledProperty, "IsNextImageAvailable");
- nextButton.SetBinding(Control.CommandProperty, "NextButtonCommand");
+
+ nextButton.BindingContextChanged += (sender, e) =>
+ {
+ if (nextButton.BindingContext is WallpaperViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ nextButton.SetBinding(session, ButtonBindings.IsEnabledProperty, "IsNextImageAvailable");
+ nextButton.SetBinding(session, ButtonBindings.CommandProperty, "NextButtonCommand");
bottomView.Add(nextButton);
}
Text = MainPage.gadgetResourceManager.GetString(nameof(LanguageResource.IDS_SAVE)),
Margin = AppCommon.saveButtonMargin,
};
- SaveButton.SetBinding(Control.CommandProperty, "SetWallpaperCommand");
+
+ var session = new BindingSession<WallpaperViewModel>();
+
+ SaveButton.BindingContextChanged += (sender, e) =>
+ {
+ if (SaveButton.BindingContext is WallpaperViewModel model)
+ {
+ session.ViewModel = model;
+ }
+ };
+ SaveButton.SetBinding(session, SaveButtonBindings.CommandProperty, "SetWallpaperCommand");
SaveButton.Hide();
appBar = new AppBar()