How to show a lot of images without setting visibility in AS3? - arrays

I have made a quiz game and I want to be able to show an image right after a user answered correctly. The problem is i have a bunch of questions and images that it becomes tedious to set visibility for each and every image. How do I optimize this procedure. I was thinking of maybe placing the images in an array but i don't really know if its possible or to make it show up in the place that i want.

As I understood, the problem is that you have N images and you iterate each time over the whole set to set the visibility. In your case I would (as you suggested) create an array of those images and few helper functions. Some basic example:
private var imageVector: Vector.<DisplayObject>; // this vector holds all your images
private var currentImage: DisplayObject; // the image that is shown currently
private function createAndFillImages():void {
imageVector = new Vector.<DisplayObject>();
imageVector.push(image1);
imageVector.push(image2);
//... etc. it depends on how your images are presented.
}
private function onAnswerGiven():void {
const img: DisplayObject = ... // pick the right image here
showImage(img)
}
private function showImage(img: DisplayObject):void {
if (currentImage != null) currentImage.visible = false;
currentImage = img;
// ... do the positioning here
currentImage.visible = true;
}

Related

Find Parent Block properties from child block in episerver

Is there a way in episerver to find a block hierarchy.
The structure that I have is
Carousal Block includes ContentArea property for Carousal Items
Carousal Item1
string
iselection factory
Carousal Item2
string
iselection factory
In Carousal Item 1,I have a selection factory .I need to fetch Carousal Block properties within this selection factory.
Any help is appreciated.
Thanks in advance.
Short answer, no, there isn't a way since blocks doesn't inherit structure that way. They can be used anywhere. Thus if you ask for the parent of a block it will always return the SysContentAssetFolder.
To solve your problem (I'm certain there are other ways as well) I'd go for a usage approach. E.g. where is the block used and find the owner, block instances will refer to parents as owners since it is an instance that can have multiple parents/owners.
Now that we know that here's some code
public class ImageBlockController : BlockController<ImageBlock>
{
private readonly IContentRepository contentRepository;
private readonly IContentTypeRepository contentTypeRepository;
public ImageBlockController(IContentRepository contentRepository, IContentTypeRepository contentTypeRepository)
{
this.contentRepository = contentRepository;
this.contentTypeRepository = contentTypeRepository;
}
public override ActionResult Index(ImageBlock currentBlock)
{
var blockContent = (IContent)currentBlock;
// Get block references
var usageReferences = contentRepository.GetReferencesToContent(blockContent.ContentLink, false);
if(usageReferences.Count() == 1)
{
// easy peasy, only one usage
var owner = contentRepository.Get<IContent>(usageReferences.First().OwnerID);
// example
var ownerType = contentTypeRepository.Load(owner.ContentTypeID);
if (ownerType.ModelType == typeof(ImageBlock))
{
// do stuff
}
}
else
{
// handle if the block is used at multiple locations
// ...
}
return PartialView(currentBlock);
}
}
The trick in this example is to get all references contentRepository.GetReferencesToContent to the loaded block, if we are satisfied with the result do something and move on. In the case you have multiple usageReferences you may have to search the loaded page for the correct owner block. In that case load the IPageRouterHelper, fetch the current page using something like var parentPage = contentRepository.Get<IContent>(pageRouteHelper.Page.ContentLink); and match the usageReferences to the items in the contentarea.

best approach to open a pop up window for large data

i am new to wpf and i need to open up a pop up a new window on grid row click which contains lots of data and controls on it.i am confused with the correct approach. i am using mvvm pattern.should i make a window control or user control or something else. and how to open that pop up inside a function. please help with example
If I need to display a new Window in my MVVM-Application I use the following approach:
At first I have an interface with a method to show the new dialog:
internal interface IDialogManager
{
void DisplayData(object data);
}
And an implementation like:
internal class DialogManager : IDialogManager
{
public void DisplayData(object data)
{
LotOfDataViewModel lotOfDataViewModel = new LotOfDataViewModel(data);
LotOfDataView lotOfDataView = new LotOfDataView
{
DataContext = lotOfDataViewModel
};
lotOfDataView.ShowDialog();
}
}
LotOfDataViewModel and LotOfDataView are the new Dialog where you want to show your data.
In your actual ViewModel you introduce a new property like:
private IDialogManager dialogManager;
private IDialogManager DialogManager
{
get { return dialogManager ?? (dialogManager = new DialogManager()); }
}
And the you can show your large data with:
DialogManager.DisplayData(myData);

How to show computed property values in EPiServer 8?

In page edit mode I want to show a read-only text that is based on a page property value. The text could for example be "A content review reminder email will be sent 2015-10-10", where the date is based on the page published date + six months (a value that will be configurable and therefore can change anytime). So far I've tried to accomplish something like this by adding another property on the page.
I've added the property CurrentReviewReminderDate to an InformationPage class we use. In page edit mode the property name is shown, but it doesn't have a value. How do I do to show the value in page edit mode (preferably as a label)?
[CultureSpecific]
[Display(
Name = "Review reminder date",
Description = "On this date a reminder will be sent to the selected mail to remember to verify page content",
Order = 110)]
[Editable(false)]
public virtual string CurrentReviewReminderDate
{
get
{
var daysUntilFirstLevelReminder =
int.Parse(WebConfigurationManager.AppSettings["PageReviewReminder_DaysUntilFirstLevelReminder"]);
if (CheckPublishedStatus(PagePublishedStatus.Published))
{
return StartPublish.AddDays(daysUntilFirstLevelReminder).ToString();
}
return "";
}
set
{
this.SetPropertyValue(p => p.CurrentReviewReminderDate, value);
}
}
EPiServer internally uses the GetPropertyValue method (i.e. the opposite of SetPropertyValue) when retrieving content for the UI.
This makes sense, otherwise your "made-up" value would be stored as the real value whenever the content is saved. This would make fall-back values etc impossible to implement.
So, this is by-design (and quite wisely so) in EPiServer. :)
However, you can customize how properties work by:
Using custom editors by applying UI hints
Modifying property metadata (for example, to display a generated value as a watermark in a textbox without interfering with the actual value being saved)
I could be misunderstanding what you're trying to do, but off the top of my head it looks like a custom editor could be a viable option for your use case?
Another solution would be to hook into the LoadedPage-event and add the value from there. This might not be the best way performance-wise since you need to do a CreateWritableClone, but depending on the site it might not matter.
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class EventInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
ServiceLocator.Current.GetInstance<IContentEvents>().LoadedContent += eventRegistry_LoadedContent;
}
void eventRegistry_LoadedContent(object sender, ContentEventArgs e)
{
var p = e.Content as EventPage;
if (p != null)
{
p = p.CreateWritableClone() as EventPage;
p.EventDate = p.StartPublish.AddDays(10);
e.Content = p;
}
}
}

SurfaceDragDrop never seems to end, object seems stuck in eternal (non)manipulation

I'm developing a WPF application for the Surface, and have run into a bug which neither I nor my colleagues know the answer to.
I have a situation when the user can drag things from a box. The box is just an image, and when touching it, another image is spawned and is the object that gets the interaction, i.e. gets dragged and dropped. The whole dragging is performed with SurfaceDragDrop.BeginDragDrop(...). Upon drop, the object simply disappears.
Now the problem is that occasionally (seems to be when input comes rapidly, just hammering the screen and not actually dragging the objects) the spawned item never despawns, i.e. it remains on screen even when input has been removed. It is possible to intereact with it by touching it to continue dragging it, but it's movement and rotation is off because it appears to think there already is another finger interacting with it.
However, through debugging I have certified that there are no touches registered to the object. It's AreAnyTouchesCaptured property is false. Manipulation is however active. So what seems to happen is that it goes into some sort of manipulation which never ends.
In order to get rid of it, I've implemented a temporary solution which simply does SurfaceDragDrop.CancelDragDrop(..) on such objects that have been on screen a certain period of time without any touches captured.
I hope my description of the problem is somewhat clear, if not please ask. Below is the code used to spawn the objects. I have however not written it (an ex-colleague did), I'm just stuck with the debugging:
private void item_PreviewTouchDown(object sender, TouchEventArgs e)
{
var box = sender as Canvas;
var imgpath = String.Format(#"[someimgpath].png");
var bmp = new BitmapImage(new Uri(imgpath, UriKind.RelativeOrAbsolute));
Image draggedItem = new Image { Source = bmp, Stretch = Stretch.None, Width = bmp.Width, Height = bmp.Height };
draggedItem.UpdateLayout();
var touchPoint = e.TouchDevice.GetTouchPoint(box);
var itemX = touchPoint.Position.X - draggedItem.Width / 2.0;
var itemY = touchPoint.Position.Y - draggedItem.Height / 2.0;
box.Children.Add(draggedItem);
draggedItem.SetValue(Canvas.LeftProperty, itemX);
draggedItem.SetValue(Canvas.TopProperty, itemY);
draggedItem.Visibility = System.Windows.Visibility.Hidden;
//We should perfom drag-and-drop when the size of the draggedItem is updated, since
//BeginDragDrop uses ActualWidth and ActualHeight property
draggedItem.SizeChanged += (o, ev) =>
{
List<InputDevice> devices = new List<InputDevice>();
devices.Add(e.TouchDevice);
foreach (TouchDevice touch in box.TouchesCapturedWithin)
{
if (touch != e.TouchDevice)
{
devices.Add(touch);
}
}
var img = new Image { Source = draggedItem.Source, Stretch = Stretch.None, Width = bmp.Width, Height = bmp.Height };
img.SetValue(Canvas.LeftProperty, itemX);
img.SetValue(Canvas.TopProperty, itemY);
var cursor = SurfaceDragDrop.BeginDragDrop(box, draggedItem, img, draggedItem, devices, DragDropEffects.Move);
};
e.Handled = true;
}

Silverlight Chart Question

I haven't enough rep points to post an image yet but given a Silverlight 4 chart example using ColumnSeries, how can I make each of the sub columns within a single column that are currently stacked up on top of each other sit side by side?
e.g Column NVQ2 shows value columns for 5 different locations, Column NVQ3 shows value columns for 5 different locations
I need the locations to sit side by side and not be stacked on top of each other.
Code for the graph:
foreach (ER_Location theLocation in UserSelections.TheDataSet.ER_Locations)
{
ER_Year myYear = (ER_Year)SeriesSelection.SelectedItem;
ColumnSeries newSeries = new ColumnSeries();
newSeries.ItemsSource = UserSelections.GetDataRowsByYearAndLocation(theLocation.Location_ID, (int)myYear.Year);
newSeries.IndependentValueBinding = new System.Windows.Data.Binding("Variable_ID");
newSeries.DependentValueBinding = new System.Windows.Data.Binding("Value");
newSeries.Title = theLocation.Name;
newSeries.IsSelectionEnabled = true;
MainChart.Series.Add(newSeries);
}
Update:
This is how the chart is rendering at present:
My guess is your code has the following using statement:-
using System.Windows.Controls.DataVisualization.Charting.Compatible
There are actually two different types with the name ColumnSeries. One is in the above namespace and it derives from StackedColumnSeries.
However the original non-stacked ColumnSeries exists in the main Charting namespace. This type will place each column side-by-side. Hence I suspect all you need to do is eliminate the extra .Compatible from your using:-
using System.Windows.Controls.DataVisualization.Charting;
You will have to create a class with the color property.
Example,
public class MyColor
{
public Brush ChartColor { get; set; }
}
then create a list of your favorite colors like
List<MyColor> colorList = new List<MyColor>
{
new MyColor
{ ChartColor = new SolidColorBrush(Colors.Blue)},
new MyColor
{ ChartColor = new SolidColorBrush(Colors.Green) },
...
...
}
From Xaml, bind the background color of the datapoint to ChartColor

Resources