Application to display food names - xaml

I am trying to learn, and I want to create a application that works like this: When they click a button, it will choose a random food(for example baked potato), and whey they click the label(or button) with the food, the recipe for that food will open in a browser.
I have tried making a list or some sort, but not sure how to do this:
<local:People x:Food="ArrayFood">
<sys:String Pasta="One" URL="http://food.com/pasta"/>
<sys:String Corn="Two" URL="http://food.com/corn"/>
<sys:String Salsa="Three" URL="http://food.com/Salsa"/>
</local:People>

I think the problem you're running into is the String type doesn't have those properties of Pasta, Corn, Salsa, or URL.
Probably the easiest thing is not to store that in the resource dictionary at all. I would store a list of custom objects in the ViewModel.
Something like:
public class Food
{
public Food() {}
public Food(string name, string url) {Name=name;Url = url;}
public string Name {get; set;}
public string Url {get; set;}
}
public class MyViewModel
{
public List<Food> Foods {get;set;} = new List<Food>
{
new Food("Corn", "http://..."),
new Food("Pasta", "http://blah/pasta" )
}
.. other view model stuff ..
}
Then bind it to a list view. When they tap, then visit the url

Related

Adding warehouse selector to the custom field in acumatica

I created a custom field and trying to add the warehouse selector to it.I try to read from the customization guide and tried it but,the selector does not show up in the custom field.
This is the code I tried.
#region UsrCustomSite
[PXDBInt]
[PXUIField(DisplayName="Warehouse", Visibility = PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(Search<IN.INSite.siteCD>),typeof(IN.INSite.descr),DescriptionField =(typeof(IN.INSite.siteCD)),SubstituteKey =(typeof(IN.INSite.siteCD)),DirtyRead =true)]
public virtual int? UsrCustomSite { get; set; }
public abstract class usrCustomSite : PX.Data.BQL.BqlInt.Field { }
#endregion
Am I missing something here?
I would try changing
[PXSelector(typeof(Search<IN.INSite.siteCD>)
to
[PXSelector(typeof(Search<IN.INSite.siteID>)
You are storing an int so you want the id, the substitute Key setting will make it so that the UI will show the CD.

sitefinity widget using query string

I like to build a widget that will take in the query string as parameters. Is there a build in method for this in sitefinity? Or is this something I have to do in code? I like to leverage sitefinity toolset .
domain.com/shoes?type=sneakers&sort=price_ascending
namespace SitefinityWebApp.Mvc.Controllers
{
[ControllerToolboxItem(Name = "Shoes", Title = "Shoes", SectionName = "MVC")]
public class ShoesController : Controller
{
public string type{ get; set; }
public string sort{ get; set; }
Should take in routed parameters like a regular MVC controller. So like
public ActionResult Index(string type, string sort){
this.sort = sort;
this.type = type;
....
}
There's nothing to automatically hydrate those public properties (and thank god, can you imagine the havok if someone could change them arbitrarily?)
But you can use Telerik.Sitefinity.Services.SystemManager.CurrentHttpContext to get the HTTP context that has the regular Request.Querystring to use.
Think of Sitefinity more as like a regular ASP.NET MVC site, with API helpers instead of a magic "do it the sitefinity way" kinda thing you know :) The ability to have multiple controllers on a page is GREAT.

How can I bind sample data from a variable of type List<string> inside a class to the XAML (design) page

I've been making use of binding to sample data so that I can get a feel of what the app is going to look like during runtime.
Things have been going great until I had to bind to a List<>. I made a sample application to demonstrate the problem.
Person.cs
public string FullName { get; set; }
public int Age { get; set; }
public string Sex { get; set; }
public List<string> Friends { get; set; }
MainViewModelSampleData.xaml
<vm:MainViewModel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:StackoverflowQuestion.ViewModels">
<vm:MainViewModel.Items>
<vm:Person FullName="Homer Simpson" Age="45" Sex="Male" />
<vm:Person FullName="Bruce Wayne" Age="32" Sex="Male" Friends="" />
</vm:MainViewModel.Items>
I can get the design view to correctly shows the string FullName, int Age, and string Sex.
What I don't know and can't figure out is how to bind data from List<string> Friends so that I can view it on the design view.
The solution is 'extracting' the Friends value
<vm:Person FullName="Bruce Wayne" Age="32" Sex="Male">
<vm:Person.Friends>
<x:String>First</x:String>
<x:String>Second</x:String>
</vm:Person.Friends>
Depending on the version of App x:String is necessary or the literal directly
<vm:Person FullName="Bruce Wayne" Age="32" Sex="Male">
<vm:Person.Friends>
First
Second
</vm:Person.Friends>
And the last option is add the following namespace
xmlns:System="clr-namespace:System;assembly=mscorlib"
<phone:PhoneApplicationPage.DataContext>
<local:Person Name="ww">
<local:Person.Friends>
<System:String>one</System:String>
<System:String>one</System:String>
</local:Person.Friends>
</local:Person>

Should I have both text and value in my model for a property that is selected from dropdownlist

In ASP.NET MVC application I have a model named CarSearchCriteria:
public class CarSearchCriteria{
public int CarMake {get;set;} // This is selected from a dropdownlist
public int YearOfFirstReg {get;set;}
public string ModelVariant {get;set}
}
I have two views - one for editing and the other one for viewing. In the editing view for the CarMake property I can do the following. I know I could have used DropDownListFor but didn't want to mess with SelectList for the time being:
<select name="CarMake">
<option value="1">BMW</option>
<option value="2">Mercedes</option>
<option value="3">Toyota</option>
</select>
So the model binding mechanism will easily bind the selected value to the appropriate model property. But what about the reading mode. I can't show 1s or 2s. I need to show BMW, Mercedes and so on. My question is what is the preferred way, do I have to have a property name that holds the actual textual information, something like CarMakeText?
You could have both the identifier (which you currently have) as well as the Make object itself. The latter would never need to be accessed when building the model, but can be accessed when reading the model. A lazy-loaded read-only property often works well for that. Something like this:
public int CarMakeID { get; set; }
public Make CarMake
{
get
{
if (CarMakeID == default(int))
return null;
// fetch the Make from data and return it
}
}
Naturally, this depends a lot on what a Make actually is and where you get it. If there's just some in-memory list somewhere then that should work fine. If fetching an instance of a Make is a little more of an operation (say, fetching from a database) then maybe some in-object caching would be in order in case you need to access it more than once:
public int CarMakeID { get; set; }
private Make _carMake;
public Make CarMake
{
get
{
if (CarMakeID == default(int))
return null;
if (_carMake == null)
// fetch the Make from data and save it to _carMake
return _carMake;
}
}
David's solution is just fine but for some reason I find my own solution to better fit my needs and besides that I find it more elegant. So basically what I do is I create a class that holds the textual descriptions of all the properties that keep just ID. For example, I have the following model:
public class EmployeeModel{
public int EmployeeID {get;set;}
public string FullName {get;set}
*public int DepartmentID {get;set}
*public int SpecialityID {get;set;}
public int Age {get;set;}
}
The properties marked with asterisk are the properties that keep ids of possible many predefined options and when showing we're supposed to show the actual descriptions, not the number representations. So for this purpose, we create a separate class:
public class EmployeeTextValues{
public string DepartmentName {get;set;}
public string SpecialityName {get;set;}
}
And then I just add this class as a property to my model:
public EmployeeTextValues TextValues {get;set;}
After that, it's quite easy to access it from anywhere, including Razor.
P.S. I'm sure that a lot of people will tend to do the following before initializing this property:
Employee emp=new Employee;
emp.Age=25;
emp.TextValues.DepartmentName="Engineering";// Don't do this
If you try to access or set Textvalues.Someproperty you'll get Object reference not set to an instance of an object. So do not forget to set TextValues first to some initialized object. Just a kind reminder, that's all.

Help with strange relationship

I have an object called "Comment" now a Comment can be associated with a "News" article OR a "Feature" article or a "Product". So will look something like:
public class Comment
{
[BelongsTo]
public Feature Feature
{get;set;}
[BelongsTo]
public News News
{get;set;}
[BelongsTo]
public Product Product
{get;set;}
}
Now obviously only 1 Feautre, Product, or News will be populated at a time, and all implement interface "IContent". So how do I get one property like:
[BelongsTo(Type = Change type at runtime!!)]
public IContent Content
{get;set;}
Any idea how to structure this?
Use [Any]. Docs about this here and here.