So I'm coding in my toolbar items to sort through my data, but on iOS the images show up but on android it does the 3 dots like it's supposed to. I don't know if this is a bug with MAUI (I didn't see anything in the git about it). I know the secondary order is supposed to have the dots by default, but I'm pretty sure they shouldn't get overridden by pictures.
Here's my code for the toolbars:
public void SortByLocation()
{
view_model_.SortMethod = Utilities.PlanSortMethod.Distance;
sort_method_ = view_model_.SortMethod;
sort_method_string_ = ToolbarItems[0].Text = sort_by_location_string;
}
public void SortByName()
{
view_model_.SortMethod = Utilities.PlanSortMethod.Name;
sort_method_ = view_model_.SortMethod;
sort_method_string_ = ToolbarItems[0].Text = sort_by_name_string;
}
public void SortByNewest()
{
view_model_.SortMethod = Utilities.PlanSortMethod.DateLatest;
sort_method_ = view_model_.SortMethod;
sort_method_string_ = ToolbarItems[0].Text = sort_by_recent_string;
}
public void SortByOldest()
{
view_model_.SortMethod = Utilities.PlanSortMethod.DateEarliest;
sort_method_ = view_model_.SortMethod;
sort_method_string_ = ToolbarItems[0].Text = sort_by_earliest_string;
}
private void SortByLabelTapped()
{
// Do nothing for now. Ideally we would pop up the toolbar, but am unsure how to do it
}
private IList<ToolbarItem> GetSortToolbarItems()
{
var list = new List<ToolbarItem>();
// Add default item
list.Add(
new ToolbarItem(
sort_method_string_,
"mow.png",
SortByLabelTapped,
ToolbarItemOrder.Primary, 0)
);
// Add options to choose from
list.Add(
new ToolbarItem(
sort_by_location_string,
"mow.png",
SortByLocation,
ToolbarItemOrder.Secondary, 0)
);
list.Add(
new ToolbarItem(
sort_by_name_string,
"mow.png",
SortByName,
ToolbarItemOrder.Secondary, 1)
);
list.Add(
new ToolbarItem(
sort_by_recent_string,
"mow.png",
SortByNewest,
ToolbarItemOrder.Secondary, 2)
);
list.Add(
new ToolbarItem(
sort_by_earliest_string,
"mow.png",
SortByOldest,
ToolbarItemOrder.Secondary, 3)
);
return list;
}
I need the 3 dots to show up on iOS.
Related
I am looking a friends code to implement google charts into my mvc project.
I have a model that I am pulling data from:
public partial class HoursPerSite
{
public string SiteName { get; set; }
public Nullable<decimal> SiteHours { get; set; }
}
The chart has rendered and it looks good but the legend is showing SiteHours and not SiteName as I'd like it to.
Here is the controller part:
// HOLIDAY PIE START
ViewBag.msg = db.HoursPerSites.Count().ToString();
var query = from r in db.HoursPerSites
select new { Count = r.SiteHours, Value = r.SiteHours };
var result2 = query.ToList();
var datachart2 = new object[result2.Count];
int l = 0;
foreach (var i in result2)
{
datachart2[l] = new object[] { i.Value.ToString(), i.Count };
l++;
}
string datastr2 = JsonConvert.SerializeObject(datachart2, Formatting.None);
ViewBag.dataj2 = new HtmlString(datastr2);
// HOLIDAY PIE END
I'd like it so the pie chart legend/key shows the site not the hours.
Not sure but is this:
select new { Count = r.SiteHours, Value = r.SiteHours };
Not supposed to be this: (SiteName):
select new { Count = r.SiteHours, Value = r.SiteName };
Also, your naming is very bad if I may say. That will not make your future work easier. Try naming your variables and obejects more specifically.
EDIT:
You can make use of Regions instead of code comments for example which will make seperation/ordering/viewing of code parts/sections much easier
Naming your variables better will make your life but also other
people working on/with your code easier
I would change your current code to this:
Please note that I don't have any editor and that there could be syntax errors
#region Holiday Pie Chart
ViewBag.msg = db.HoursPerSites.Count().ToString();
var queryHoursPerSites = from r in db.HoursPerSites
select new { Count = r.SiteHours, Value = r.SiteHours };
var resultsQueryHoursPerSites = queryHoursPerSites.ToList(); // or HoursPerSitesCollection
var holidayPieChart = new object[resultsQueryHoursPerSites.Count];
int counter = 0; //
foreach (var record in resultsQueryHoursPerSites)
{
holidayPieChart[counter] = new object[] { record.Value.ToString(), record.Count };
counter++;
}
string deserialisedResults = JsonConvert.SerializeObject(holidayPieChart, Formatting.None);
// no idea what dataj2 is here ...
ViewBag.dataj2 = new HtmlString(deserialisedResults);
#endregion
I am sure there is even more to "improve" or "change" but that would in my opinion already be an improvement.
I am sure others can elaborate even better on what I am suggesting here :)
I am working at chat with stickers on Mono C# with GTK# GUI. While googling i have founded that best widget for this purpose is TextView. Problem in creating ListStore for column with multiple renderers:
TreeView messageLog=new TreeView();
#Creating a column
TreeViewColumn messageColumn = new TreeViewColumn();
messageLog.AppendColumn(messageColumn);
#Creating model for tree
ListStore messageStore = new ListStore(typeof(string), typeof(Gdk.Pixbuf));
messageLog.Model = messageStore;
#Packing 2 renderers into column
CellRendererText textCell = new CellRendererText();
messageColumn.PackEnd(textCell, true);
messageColumn.AddAttribute(textCell, "text", 0);
CellRendererPixbuf stickerCell = new CellRendererPixbuf();
messageColumn.PackStart(stickerCell, false);
messageColumn.AddAttribute(stickerCell, "pixbuf", 1);
Add text to TreeView:
messageStore.AppendValues(value);
This way, i can add pictures to TreeView only with:
messageStore.AppendValues(null, new Gdk.Pixbug("red.png");
But it shows like in new column. Is there a better way to define ListStore or append values so picture will be shown in same column as message? Or maybe there is a better widget for this purpose?
You were right, I've been able to do it (more than one item in a single column), following (or inferring from) the Mono's Gtk# tree view tutorial.
namespace TreeViewMultipleRenderers
{
public class MainWindowView: Gtk.Window
{
public MainWindowView()
: base( Gtk.WindowType.Toplevel )
{
this.SetGeometryHints( this,
new Gdk.Geometry { MinHeight = 400, MinWidth = 600 },
Gdk.WindowHints.MinSize );
this.Build();
}
void BuildIcons()
{
this.IconYes = new Gdk.Pixbuf(
System.Reflection.Assembly.GetEntryAssembly(),
"TreeViewMultipleRenderers.Res.yes.png", 16, 16 );
this.IconNo = new Gdk.Pixbuf(
System.Reflection.Assembly.GetEntryAssembly(),
"TreeViewMultipleRenderers.Res.no.png", 16, 16 );
}
Gtk.TreeView BuildTreeView()
{
var toret = new Gtk.TreeView();
// Index column
var columnIndex = new Gtk.TreeViewColumn {
Title = "#"
};
var indexRenderer = new Gtk.CellRendererText();
columnIndex.PackStart( indexRenderer, expand: true );
columnIndex.AddAttribute( indexRenderer, "text", 0 );
// Data column
var columnData = new Gtk.TreeViewColumn {
Title = "Mixed column"
};
var dataRenderer1 = new Gtk.CellRendererPixbuf();
columnData.PackStart( dataRenderer1, expand: false );
columnData.AddAttribute( dataRenderer1, "pixbuf", 1 );
var dataRenderer2 = new Gtk.CellRendererText();
columnData.PackStart( dataRenderer2, expand: true );
columnData.AddAttribute( dataRenderer2, "text", 2 );
toret.AppendColumn( columnIndex );
toret.AppendColumn( columnData );
// Model
var store = new Gtk.ListStore( typeof( string ), typeof( Gdk.Pixbuf ), typeof( string ) );
toret.Model = store;
store.AppendValues( "1", this.IconYes, "works" );
store.AppendValues( "2", this.IconNo, "does not work" );
return toret;
}
void Build()
{
this.BuildIcons();
this.TreeView = this.BuildTreeView();
this.Add( this.TreeView );
}
public Gtk.TreeView TreeView {
get; set;
}
public Gdk.Pixbuf IconYes {
get; private set;
}
public Gdk.Pixbuf IconNo {
get; private set;
}
}
}
I can't see any important difference with the relevant parts of the code you posted, so I guess the problem must be elsewhere. You can find this code in the GtkTreeViewMultipleRenderers Github repository. I've also uploaded an executable in the releases section of the repository.
Hope this helps.
private int SumOfNodes()
{
ManufacturingDataModel MDM = new ManufacturingDataModel();
Test t = new Test(MDM);
List<Hardware> SumOfHardware = t.GetHardware().FindAll(x => x.Nodes != 0);
int SumOfNodes = 0;
foreach (Hardware i in SumOfHardware )
{
SumOfNodes += i.Nodes;
}
return SumOfNodes;
}
private int SumOfRepeaters()
{
ManufacturingDataModel MDM = new ManufacturingDataModel();
Test t = new Test(MDM);
List<Hardware> SumOfHardware = t.GetHardware().FindAll(x => x.Repeaters != 0);
int SumOfRepeaters = 0;
foreach (Hardware i in SumOfHardware)
{
SumOfRepeaters += i.Repeaters;
}
return SumOfRepeaters;
}
private int SumOfHubs()
{
ManufacturingDataModel MDM = new ManufacturingDataModel();
Test t = new Test(MDM);
List<Hardware> SumOfHardware = t.GetHardware().FindAll(x => x.Hubs != 0);
int SumOfHubs= 0;
foreach (Hardware i in SumOfHardware)
{
SumOfHubs += i.Hubs;
}
return SumOfHubs;
}
private string Month()
{
DateTime now = DateTime.Now;
string month = DateTime.Now.ToString("MMMM");
return month;
}
private void DisplayData()
{
SeriesCollection = new SeriesCollection
{
new ColumnSeries
{
Title = "Nodes",
Values = new ChartValues<int> { SumOfNodes() }
},
};
SeriesCollection.Add
(
new ColumnSeries
{
Title = "Repeaters",
Values = new ChartValues<int> { SumOfRepeaters() }
}
);
SeriesCollection.Add
(
new ColumnSeries
{
Title = "Hubs",
Values = new ChartValues<int> { SumOfHubs() }
}
);
Labels = new[] { Month() };
Formatter = value => value.ToString("N");
DataContext = this;
}
enter image description here
At this points I've managed to create an app that adds/removes and updates my items on my database. I'm also planning to add some stats (Started off with graph visualisation) but I'm facing an issue.
I want to seperate columns based on months. So for example as seen by the image attached no matter how many items i add , remove or update the total amount for each item is added to Decemeber. But when January comes any newly added modification to the quantity of my items I would like to see adjacent to the Decemeber one.
P.S.: There is alot of code repitition which will accounted for later on.
I've managed to put something together regarding my answer above which may be usefull for someone in the future
What I've done was to
1) Get my data from my db.
2) Find the Month of interest using LINQ queries **
instead of selecting the items (i.e repeaters, nodes)
**
3) By doing so it also accounts for the items I'm interested in during the month of interest.
4) Do an incremental foreach loop as shown in my code above.
5) Change the methodd i want to display (i.e DisplayData to DisplayDecemberData) and use in the same way as above.
6) Create further methods for the subsequent months and just add the additional information in the ChartValues object.
See Below
private int DecemberNodes()
{
ManufacturingDataModel MDM = new ManufacturingDataModel();
Test t = new Test(MDM);
List<Hardware> decembernodes = t.GetHardware().FindAll(x => x.Date.Month==12);
int DecemberSumOfNodes = 0;
foreach (Hardware i in decembernodes)
{
DecemberSumOfNodes += i.Nodes;
}
return DecemberSumOfNodes;
}
private int JanuaryNodes()
{
ManufacturingDataModel MDM = new ManufacturingDataModel();
Test t = new Test(MDM);
List<Hardware> januarynodes = t.GetHardware().FindAll(x => x.Date.Month==01);
int JanuarySumOfNodes = 0;
foreach (Hardware i in januarynodes)
{
JanuarySumOfNodes += i.Nodes;
}
private void DisplayDecemberData()
{
SeriesCollection = new SeriesCollection
{
new ColumnSeries
{
Title = "Nodes",
Values = new ChartValues<int> { DecemberNodes() }
},
};
private void DisplayJanuaryData()
{
SeriesCollection = new SeriesCollection
{
new ColumnSeries
{
Title = "Nodes",
**Values = new ChartValues<int> { DecemberNodes(), JanuaryNodes() }**
},
};
There is some code repetition and I'm pretty sure there is a more code concise way of actually doing it but for now this seems to do the trick. When I simplify the code i will post it.
I need to get a untyped QueryableCollection from a DataContext to query it. I have the following code:
printAbleListView = (ListView) printObject.FindName("printAbleListView");
// Here I like to have something like ObservableCollection<Object>
ObservableCollection<Journal> allItems = (ObservableCollection<Journal>) printAbleListView.DataContext;
// Add the page to the page preview collection
for (int i = 0; i <= (allItems.Count()/30); i++)
{
printAbleListView.DataContext = null;
printAbleListView.DataContext = allItems.Skip(30 * i).Take(30);
document.SetPreviewPage((i + 1), printObject);
}
The goal is to print out any ListView in a Metro-Style Windows 8 app. Currently it is typed to the Journal DataType, but I like to have it untyped so the function can be reused for every ListView, not only for the Journal ones. Hw can i archive this?
Example:
void GeneratePreview<T>(int itemsPerPage)
{
var printAbleListView = (ListView)printObject.FindName("printAbleListView");
var allItems = (ObservableCollection<T>)printAbleListView.DataContext;
// Add the page to the page preview collection
for (int i = 0; i <= (allItems.Count()/itemsPerPage); i++)
{
printAbleListView.DataContext =
allItems.Skip(itemsPerPage * i).Take(itemsPerPage);
document.SetPreviewPage((i + 1), printObject);
}
}
For untyped access, you can actually use the fact that ObservableCollection<T> supports non-generic ICollection:
void GeneratePreview(int itemsPerPage)
{
var printAbleListView = (ListView)printObject.FindName("printAbleListView");
var allItems = (ICollection)printAbleListView.DataContext;
var slice = new List<object>(itemsPerPage); // cannot use ArrayList for Win8 apps
var pageNo = 1;
foreach (var item in allItems)
{
slice.Add(item);
if (slice.Count % itemsPerPage == 0)
{
// flush
printAbleListView.DataContext = slice;
document.SetPreviewPage(pageNo, printObject);
// and restart
pageNo++;
slice.Clear();
}
}
if (slice.Count != 0) // flush the rest
{
printAbleListView.DataContext = slice;
document.SetPreviewPage(pageNo, printObject);
}
// clean up
printAbleListView.DataContext = null;
}
I am working with a link list. I have set my constructor to take an array named ax with a set of already defined items. I also decided to have an input box which through a BtnAddTree_Click appends the new item to the list ax. But instead of appending to the list ax it creates a whole new separate list. How can I append items to the array list ax through my AddTree function?
public ListForTrees(IEnumerable<fruit_trees> trees)
{
foreach (fruit_trees t in trees)
{
this.AddTree(t);
}
}
public void AddTree(fruit_trees new_tree)
{
fruit_trees current = first_tree;
if (count == 0)
{
first_tree = new_tree;
last_tree = new_tree;
count = 1;
}
else if (count != 0)
{
if (new_tree.tree_price <= first_tree.tree_price)
{
new_tree.next_tree = first_tree;
first_tree = new_tree;
}
else if (new_tree.tree_price >= last_tree.tree_price)
{
last_tree.next_tree = new_tree;
last_tree = new_tree;
}
else
{
while (new_tree.tree_price > current.next_tree.tree_price)
{
current = current.next_tree;
}
new_tree.next_tree = current.next_tree;
current.next_tree = new_tree;
}
count++;
}
}
}
ListForTrees mainlist = new ListForTrees();
private void BtnGo_Click(object sender, EventArgs e)
{
fruit_trees[] ax = { new fruit_trees("cherry", 48, 12.95, 3),
new fruit_trees("pine", 36, 9.95, 8),
new fruit_trees("oak", 60, 14.95, 2),
new fruit_trees("peach", 54, 19.95, 3),
new fruit_trees("pear", 36, 11.85, 2),
new fruit_trees("apple", 62, 13.45, 5)
};
mainlist = new ListForTrees(ax);
fruit_trees current = mainlist.first_tree;
while (current != null)
{
current = current.next_tree;
}
}
}
}
It doesn't seem to be creating a new separate list. I tested out the following code with yours:
public class TreeTester
{
public static void Main(string[] args)
{
var list = new ListForTrees(
new[] { new fruit_trees("tree10",10,10,10), new fruit_trees("tree2",2,2,2) });
list.AddTree( new fruit_trees("tree3",3,3,3) ); // middle
list.AddTree( new fruit_trees("tree1",1,1,1) ); // first
list.AddTree( new fruit_trees("tree50",50,50,50) ); // last
list.AddTree( new fruit_trees("tree5",5,5,5) ); // middle
Console.Write(list);
}
}
And got the following output, which seems correct.
tree1 1 1 1
tree2 2 2 2
tree3 3 3 3
tree5 5 5 5
tree10 10 10 10
tree50 50 50 50
What is the expected behavior, if this is not correct? Clearly these items are all being added to the original list, since they're present when I iterate through the list.
By the way, I also added the following ToString function to your ListForTrees class; it makes debugging easier.
public override string ToString()
{
string s = "";
for (var tree=first_tree; tree!=null; tree = tree.next_tree)
s += tree + "\n";
return s;
}
Edit: I must comment that you may find it helpful to cleanup your code a bit in trying to understand where it is going wrong. For example, your ListForTrees(fruit_trees new_tree) constructor does the same exact thing as calling Add(new_tree) would. Also, think about three cases you have in Add, under else if (count != 0) -- perhaps there's a way they could elegantly combined into one general while loop? It makes it easier to analyze, and (potentially) less error-prone.