I have a main view that never gets destroyed and the HTML is never rerendered.
Inside this view, I add a subview.
var view = new View({ el: $(".subViewClass")})
But when I destroy this subview, its "el-class" is removed from the DOM.
So when I try to add the view again, .subViewClass is not in the DOM, and the subview is never added to it.
Is there a way to add my subview, remove it, and add it again when the parentView is never re-rendered?
My best solution is to add the .subviewClass manually every time.
var container = $(".all-views")
container.append("<div class='subView'></div>");
var view = new View({ el: $(".subViewClass")})
Related
My Xamarin Forms Application has a MainPage set to
new NavigationPage(new CarsMasterDetailPage())
where CarsMasterDetailPage : MasterDetailPage.
In CarsMasterDetailPage constructor, I set the Master property to new CarsMasterPage() and the Detail property to new CarsDetailPage(). Both CarsMasterPage and CarsDetailPage extend ContentPage.
The master page contains a list of cars and a button which has an event handler that does:
await Navigation.PushAsync(new AddCar());
The AddCar page has a button with an event handler that does:
await Navigation.PopAsync();
When I first run the app, the OnAppearing method of the master page is called. The first time the navigation pops back to the master page, OnAppearing is called again. Subsequent navigation pushes and pops don't, though.
I can get around it by adding a delegate on the master page that the add car page calls when it's done, but that feels hacky since there are page events to handle this. Does anyone know why it's not working?
In my case, I did it like this and everything works fine:
My MainPage:
MainPage = new MasterDetailPage {
Master = new MasterDetailPage1Master(),
Detail = new MyNavigationPage(new MainPageLinearList(appType))
};
So the key point was to use NavigationPage in a DetailPage. After that everything works fine.
Subscribe to the NavigationPage.Popped event:
navigationPage.Popped += OnPopped;
...
void OnPopped(object sender, NavigationEventArgs e)
{
var currentPage = (sender as NavigationPage).CurrentPage;
var removedPage = e.Page;
...
}
I have written a windows universal app under windows 10 that has a ListView.
This ListView updates every five seconds if new data if available. Its data source is an ObservableCollection that only allows a maximum of ten items to be shown, with the newest being inserted at the front of the collection. This seems to work well as you see the ListView with items slowly scrolling down the screen.
What I want to do is add some sort of colour transition to the new items in the ListView, so that when they appear, the background of the item starts off grey and fades to white. I want this effect so that a user can easily see the new item or items that have just appeared in the ListView.
The new objects added to the collection have a flag set to indicate they are new. I thought this could be used as an indicator if the animation process was able to reset this flag after the animation? Or should I look to use an event off the ListView, if there is one?
I’m new to storyboards so am not sure the best approach. Can anyone advise on the areas I should research to get the animation or even if it's possible under the UWP?
Basically, whenever a new item has been added, you want to animate its color to light gray and then animate it right back.
So the key thing is to find the event that's invoked during the item container creation. In this case, ContainerContentChanging is your friend.
Since you need to animate the color a few times during an animation, you will need ColorAnimationUsingKeyFrames rather than a normal ColorAnimation. The whole Timeline and Storyboard syntax can be a bit confusing at times so I have created a simple demo for you here. Hope it helps. :)
private void OnListViewContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (args.ItemContainer != null && !args.InRecycleQueue && args.Phase == 0)
{
var colorAnimation = new ColorAnimationUsingKeyFrames
{
// 'cause the new item comes in with an animation of which duration is about 300s, we add a little delay here to only
// animate the color after it appears.
BeginTime = TimeSpan.FromMilliseconds(300)
};
var keyFrame1 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = Colors.White };
var keyFrame2 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(400)), Value = Colors.LightGray };
var keyFrame3 = new LinearColorKeyFrame { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(1200)), Value = Colors.White };
colorAnimation.KeyFrames.Add(keyFrame1);
colorAnimation.KeyFrames.Add(keyFrame2);
colorAnimation.KeyFrames.Add(keyFrame3);
Storyboard.SetTarget(colorAnimation, args.ItemContainer);
Storyboard.SetTargetProperty(colorAnimation, "(Control.Background).(SolidColorBrush.Color)");
var storyboard = new Storyboard();
storyboard.Children.Add(colorAnimation);
storyboard.Begin();
}
}
Here's how it looks like in a demo app.
I have a TableView that is in a descendent controller of a TabViewController. The TableView has items coming from an API. There is also a create new TableItem form/controller which once it has been submitted I need it to present the ViewController with the table view, with an updated list of items from the API.
var storyBoard = this.Storyboard;
var viewController = (TabBarController)storyBoard.InstantiateViewController("TabBarController");
var tabs = viewController.ChildViewControllers;
viewController.SelectedViewController = tabs[1];
PresentViewController(viewController, true, null);
This works as expected in terms of presenting the correct view. But until I force a reload like so:
async Task RefreshAsync()
{
if (_useRefreshControl)
_refreshControl.BeginRefreshing();
if (_useRefreshControl)
_refreshControl.EndRefreshing();
BookingsTableView.ReloadData();
}
The view just displays the same items in the TableView when on the load of the page it should be querying the API and loading the list:
_bookings = await _apiService.GetBookingsForCustomer(model.CustomerEmail);
_dataSource = new BookingTableSource(_bookings, this);
BookingsTableView.Source = _dataSource;
BookingsTableView.ReloadData();
Should also note this app is only a simple proof of concept.. But how can I get it to Instantiate my TableViewController whilst still Presenting the TabBarController?
Thanks,
Danny
Solved this, just dismissed the ViewController with the booking form and called my refresh method in the ViewDidAppear override in the ViewController with the bookings TableView:
public override void ViewDidAppear(bool animated)
{
RefreshData();
}
I want to navigate to a view html file (from another view's js file) but pass in the model to be used by that view. How can I do this please.
I can generally do this when I am opening the new view in a dialog. In this case, I create the model object (var model = require('viewmodels/modeljsfile), and then creating an instance of this model and accessing the properties (var instance = new model(); instance.property1 = 'Test). I then pass this instance to my modal.
Instead of opening in view html in a modal, I want to redirect to the actual view. How can I do this please?
In the view add a Compose and state the target view/model. Note that both the View/Model can be variables from the parent view.
Be careful however as not all the life cycle events are attached (activator.js)
<div data-bind="compose: { model:someModelProperty, view:someViewProperty }"/>
http://durandaljs.com/documentation/Using-Composition.html
Is there any way to animate all the items of an ItemCollection in WP7, right now the storyboard (which is called from the codebehind) seems to be happening to only the first Item.
Also, which is the best way to access and animation inside a DataTemplate, which is assigned to an item inside another DataTemplate - doing the same thing as the top level one, does not seem to work. this is a smaple of the code i'm using to find it. the generic is from WindowsPhoneGeeks
Storyboard sb1 = (Storyboard)this.FindName("ChangeToBlack");
Storyboard sb2 = null;
StackPanel topFrame = FindFirstElementInVisualTree<StackPanel>(PartyCollection);
if (topFrame != null)
{
StackPanel s2 = FindFirstElementInVisualTree<StackPanel>(topFrame);
sb2 = (Storyboard)s2.Resources["ItemChangeToBlack"];
sb2.Begin();
}
sb1.Begin();